Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

I have a script that uses $(document).ready, but it doesn't use anything else from jQuery. I'd like to lighten it up by removing the jQuery dependency.

How can I implement my own $(document).ready functionality without using jQuery? I know that using window.onload will not be the same, as window.onload fires after all images, frames, etc. have been loaded.

1 Answer

0 votes
by (106k points)

The equivalent of $(document).ready without jQuery is DOMContentLoaded which is supported by many browsers, though not IE8:

document.addEventListener("DOMContentLoaded", function(event) { //your code

});

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...