Pure Javascript equivalent to jQuery $(document).ready()

The pure Javascript equivalent to

jquery_document_ready_example.js
$(document).ready(function() {
    // Your code goes here!

})

is

domcontentloaded_example.js
document.addEventListener("DOMContentLoaded", function() { 
    // Your code goes here!
});

Note that it’s not supported by IE8, but that should not be an issue in 2019.


Check out similar posts by category: Javascript