check element exist in jquery
snippet in javascript

jquery check if element exists

user2962

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

}

check element exist in jquery

user2034

if ($('.element').length) {
  // there is at least one element matching the selector
}

jquery check if element still exists

user5750

$(function() {
    var $button = $(".the_button");
    alert (isStale($button));
    $button.remove();
    alert (isStale($button));
});
    
function isStale($elem)
{
    return $elem.closest("body").length > 0;
};