I write a script for one page for a specific element.
On another page, it is missing, and climbs errors. Found a way to bypass errors by checking the presence of the element in this way:
var el = $(".el").html(); if (!el) { console.log('Нет элемента'); } else { console.log('Есть элемент'); }; .el { font-weight: bold; padding: 15px; font-size: 20px; color: #fff; text-shadow: 0 0 5px #125415; display: block; position: absolute; background: #43A047; } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <div class="el">Элемент</div>
$('.el').length;- Alexey Shimansky'', I would try thisif (typeof($(".el").text()) != undefined) { console.log('Нет элемента'); }if (typeof($(".el").text()) != undefined) { console.log('Нет элемента'); }- perfect