Equivalent jQuery ready event in Javascript

jQuery’s ready event does not wait for the entire page to load. It just expects that the entire DOM has been generated in Javascript’s memory and is therefore available to receive manipulation instructions.

The equivalent event in vanilla Javascript (native Javascript) is DOMContentLoaded.

I give you an example of use to make it clear.

document.addEventListener(“DOMContentLoaded”, function(event) { //code to execute when the DOM is ready to receive actions });

The load (or onload) event that has been mentioned would not be exactly the same, since it has the difference with respect to ready. Specifically, onload is fired when all page elements have finished loading. That is, it waits for all the images to be downloaded, scripts, banners, iframes… Therefore, DOMContentLoaded is usually executed before, since the DOM can be processed very quickly and some heavy images take a while to load, for example .

See also  Handlebar Manual
Loading Facebook Comments ...
Loading Disqus Comments ...