Document Ready with promise

//DOM And Page Ready (function() { 'use strict'; document.onreadystatechange = function () { if ( document.readyState === "interactive" ) { } } }()); //With Promise HTMLDocument.prototype.ready = function () { return new Promise(function(resolve, reject) { if (document.readyState === 'complete') { resolve(document); } else { document.addEventListener('DOMContentLoaded', function() { resolve(document); }); } }); } document.ready().then( // Your then stuff here );
A better way to fire Document Ready.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.