Guest
0
Q:

jquery check if element exists

// Check if an element currently exists
if ($('#element').length) {

}
10
$(document).ready(function() {
    var $myDiv = $('#DivID');

    if ( $myDiv.length){
        //you can now reuse  $myDiv here, without having to select it again.
    }


});
3
if ($('.element').length) {
  // there is at least one element matching the selector
}
8
if ($(selector).length)
0
$(function() {
    var $button = $(".the_button");
    alert (isStale($button));
    $button.remove();
    alert (isStale($button));
});
    
function isStale($elem)
{
    return $elem.closest("body").length > 0;
};
-1
if ($("#myElementID").length){
   //I exist
}
-1

New to Communities?

Join the community