Answers for "jquery run when element exists"

22

jquery check if element exists

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

}
Posted by: Guest on June-05-2020
1

jquery wait for target to load

//https://gist.github.com/chrisjhoughton/7890303

var waitForEl = function(selector, callback) {
  if (jQuery(selector).length) {
    callback();
  } else {
    setTimeout(function() {
      waitForEl(selector, callback);
    }, 100);
  }
};

waitForEl(selector, function() {
  // work the magic
});
Posted by: Guest on September-01-2020
-2

jquery check if element still exists

$(function() {
    var $button = $(".the_button");
    alert (isStale($button));
    $button.remove();
    alert (isStale($button));
});
    
function isStale($elem)
{
    return $elem.closest("body").length > 0;
};
Posted by: Guest on April-17-2020

Code answers related to "jquery run when element exists"

Code answers related to "Javascript"

Browse Popular Code Answers by Language