Created
November 29, 2012 22:35
-
-
Save Sinetheta/4172367 to your computer and use it in GitHub Desktop.
$.whenReady wait for arbitrary target to be ready
This file contains 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
$.whenReady = function(target, delay) { | |
var dfd = $.Deferred(); | |
var look = window.setInterval(function() { | |
var $target = $(target); | |
if($target.length) { | |
dfd.resolve($target); | |
window.clearInterval(look); | |
} | |
}, delay || 10); | |
return dfd; | |
}; |
This file contains 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
$.whenReady('#slowpoke').done(function($target) { | |
console.log($target.length); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We use this in SharePoint instead of _spBodyOnLoadFunctionNames. Why? Because, like everything else in SP, the native solution is unreliable and has lead to broken code and crushed dreams.