Last Updated: February 25, 2016
·
262
· malko

shortest cross platform onReady document

/**
* very poor (but short and easy) cross platform implementation to detect dom readiness
*/
function onReady(fn){
    document.body ? fn() : setTimeout(function(){ onReady(fn);},50);
};

not really a dom ready but is sufficient most of the time if all you need is ensure a body element is already present in the document.

https://gist.github.com/malko/c5403a9312e0ffe98fbb

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Related Tags
#javascript
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside