-
-
Save Pandiora/7b002ac074430bd7197b009ec2440ff0 to your computer and use it in GitHub Desktop.
Wait for an element to exist on the page with jQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// altered to version like described in comments and passing back selector | |
// to be used later with that or whatever var one chooses | |
// maxTimes should be used to not have a neverending timeout loop | |
const waitForEl = (selector, maxTimes = false, callback) => { | |
// wait for selector until it exists and pass it back | |
if (jQuery(selector).length) { | |
callback(selector); | |
} else { | |
if (maxTimes === false || maxTimes > 0) { | |
(maxTimes != false) && maxTimes-- ; | |
setTimeout(function () { | |
waitForEl(selector, maxTimes, callback); | |
}, 100); | |
} | |
} | |
}; | |
waitForEl(selector, maxTimes, (that)=>{}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment