What is the difference between 'function' and 'document. Ready()'? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is the difference between 'function' and 'document. Ready()'?

Hello everyone I have a question in Javascript language : What is the difference between 'function' and 'document. Ready()' when we want use a method after full load page?

18th May 2020, 2:15 PM
Abbas Rahimi
Abbas Rahimi - avatar
2 Answers
+ 1
The major difference is that document.ready() does not exist. You are probably referring to jquery(document).ready() method in the jQuery library. If you want to execute a statement after the DOM is loaded use this document.addEventListener('DOMContentLoaded', function(){ //statement goes here });
18th May 2020, 2:33 PM
Ore
Ore - avatar
+ 1
document.ready() initializes kind of like onload() and determines if the document is ready to interface with but is limited to jQuery if my memory serves me. A normal function sets the block and you would call it later on and is pretty standard. You could run a normal function without jQuery using vanilla JavaScript when the script is loaded too. The difference wouldn’t be terribly noticable unless you need execution to only trigger once the DOM is completely ready to interface with.
18th May 2020, 2:25 PM
Wildcard_Renegade
Wildcard_Renegade - avatar