Home Pure JavaScript equivalent of jQuery's $.ready() - how to call a function when the page/DOM is ready for it
Reply: 0

Pure JavaScript equivalent of jQuery's $.ready() - how to call a function when the page/DOM is ready for it

user1468
1#
user1468 Published in May 21, 2018, 11:16 am

This question already has an answer here:

  • $(document).ready equivalent without jQuery 31 answers

Okay, this might just be a silly question, though I'm sure there are plenty of other people asking the same question from time to time. Me, I just want to make 100% sure about it either way. With jQuery we all know the wonderful

$('document').ready(function(){});

However, let's say I want to run a function that is written in standard JavaScript with no library backing it, and that I want to launch a function as soon as the page is ready to handle it. What's the proper way to approach this?

I know I can do:

window.onload="myFunction()";

...or I can use the body tag:

<body onload="myFunction()">

...or I can even try at the bottom of the page after everything, but the end body or html tag like:

<script type="text/javascript">
   myFunction();
</script>

What is a cross-browser(old/new)-compliant method of issuing one or more functions in a manner like jQuery's $.ready()?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.420417 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO