I’m wondering if it is possible to use a jQuery deferred object to test whether or not an element is in the DOM.
Here’s kind of what I’m thinking:
function chkDOM(selector) {
if $(selector) {
return deferred.promise();
}
}
$.when(chkDOM(selector)).then(function() {
// do something
});
I don’t exactly know how to form the code to make this happen, but I hope that my question makes sense. If I can get this piece to work right, then I can essentially delay the calling of certain jquery plugins so that they actually run properly.
Thanks!
I assume that you are running a loop that periodically checks the existence of the selector:
Note that
$.whenis not needed; you can just use.doneon the deferred object directly.