Skip to content

Instantly share code, notes, and snippets.

@vvscode
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vvscode/1d973f5139e29075c588 to your computer and use it in GitHub Desktop.
Save vvscode/1d973f5139e29075c588 to your computer and use it in GitHub Desktop.
waitElement in DOM
function waitElement(selector, callback, delay) {
delay = delay || 100;
setTimeout(function() {
if(jQuery(selector).length) {
callback();
} else {
waitElement(selector, callback, delay);
}
}, delay);
}
waitElement('.test', function() {
alert(1);
});
setTimeout(function() {
jQuery(document.body).append('<div class="test">12121<div>');
}, 5000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment