Native Javascript Replacements for jQuery $(document).ready() and $(window).load()

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

2 thoughts on “Native Javascript Replacements for jQuery $(document).ready() and $(window).load()

Leave a Reply

Your email address will not be published. Required fields are marked *