Skip to content

Instantly share code, notes, and snippets.

@bultas
Last active August 29, 2015 14:04
Show Gist options
  • Save bultas/c9264cf7ce49e793bed1 to your computer and use it in GitHub Desktop.
Save bultas/c9264cf7ce49e793bed1 to your computer and use it in GitHub Desktop.
Wait for DOM element
function waitDOM(element, callback, waitTime) {
var stop = 0;
var waitTime = waitTime || 100;
var wait = setInterval( function() {
var elementDOM = document.querySelector(element);
if (elementDOM) {
clearInterval(wait);
callback();
} else {
if (stop > 100) {
clearInterval(wait);
console.log("element not found in interval");
}
stop++;
}
}, waitTime);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment