Usage:
domready(function () {
// do stuff that requires the DOM
});| /*jslint indent: 2 */ | |
| (function (global) { | |
| 'use strict'; | |
| var domready = function (callback) { | |
| if (typeof callback !== 'function') { | |
| throw new TypeError('callback is not a function'); | |
| } | |
| function loaded() { | |
| callback(); | |
| } | |
| if (global.addEventListener) { | |
| global.addEventListener('DOMContentLoaded', loaded, false); | |
| } else if (global.attachEvent) { | |
| global.attachEvent('onload', loaded); | |
| } else { | |
| loaded(); | |
| } | |
| }; | |
| global.domready = domready; | |
| }(this)); |
Usage example: