Javascript libraries certainly have their place, but I prefer doing things in native Javascript wherever possible.
A Replacement for $(document).ready()
:
Here is a native Javascript replacement for jQuery’s $(document).ready()
function, which works in all modern browsers.
document.addEventListener( 'DOMContentLoaded', function( event ) {
// Do something
});
A replacement for $(window).load()
:
window.addEventListener( 'load', function( event ) {
// Do something
});
Thanks, using simple JS is surely the best way to do this, especially for simple things like this.
what’s the difference bewteen
“document.readyState == complete” and the load event?
they both seem to do the same thing.