window.dg = { //check dom is ready or not domReady: function(callback) { (document.readyState === "interactive" || document.readyState === "complete") ? callback() : this.addEvent(document, "DOMContentLoaded", callback); }, //Event listener for all browsers addEvent: function (obj, e, callback) { if(obj.addEventListener) obj.addEventListener(e, callback, false); else if(obj.attachEvent) obj.attachEvent("on" + e, callback); }, developerGang:function(){ alert('Developer Gang'); }, init:function(){ //When DOM has been fully loaded this.domReady(function(){ dg.developerGang(); }); } } //call init dg.init();
Javascript detect DOM ready
I am going to provide you pure javascript code to check DOM is ready or not.
Please see below code,once DOM has been full loaded it will alert "Developer Gang".