What is the use of ready() function in jQuery ? Last Updated : 28 Nov, 2021 Comments Improve Suggest changes Like Article Like Report In this article, we will see how to use ready() function provided by the jQuery library. The ready() function is used to execute some javascript code only when the HTML DOM is fully loaded. We should not manipulate the DOM until it is fully loaded. ready() method comes very handy to detect when the DOM is loaded successfully. Syntax: $(selector).ready(handler) Here 'handler' is a JavaScript Function that is to be executed once the DOM is ready. The selector inside the parentheses doesn't matter. For example, the three syntaxes below mean the same thing. Example: In the below example, we are changing the text of h1 to "DOM is now ready" with the help of the ready() function which is firing when DOM is fully loaded. HTML <!DOCTYPE html> <html> <head> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"> </script> </head> <body> <h1></h1> <script> $.holdReady(true); setTimeout(() => { $.holdReady(false); }, 2000); function onDOMReady() { $().ready(() => { $("h1").text("DOM is now ready"); }); } onDOMReady(); </script> </body> </html> Output: Here we are using holdReady() function to hold the DOM ready event for 2 seconds, so that we can simulate the delay in DOM load for testing ready() function. Comment More infoAdvertise with us Next Article What is the use of ready() function in jQuery ? V vpsop Follow Improve Article Tags : Web Technologies JQuery jQuery-Methods jQuery-Questions Similar Reads What is the use of .each() function in jQuery ? The each() function in jQuery iterate through both objects and arrays. Arrays that have length property are traversed from the index 0 to length-1 and whereas arrays like objects are traversed via their properties names. Syntax: $.each('array or object', function(index, value){ // Your code }) In th 2 min read What is the use of param() method in jQuery ? In this article, we will learn about the param() method which is an inbuilt method provided by jQuery. This method is used for creating a serialized representation of an object. The method will recursively serialize deep objects for trying to work with modern languages like Ruby on Rails or Python. 3 min read What is the use of css() method in jQuery ? In this article, we will see how to use css() method to set the styles on elements dynamically using jQuery. The css() method is used to change the style property of the selected element. basically, The CSS() method is used to get the value of a certain CSS property that has been applied to a specif 2 min read What is the use of html() method in jQuery ? The html() method in jQuery is used to get the contents of the first element in the set of matched elements or is used to set the HTML contents of every matched element. It returns the content of the first matched element. This function does not accept any arguments. Syntax: $(selector).html();Appro 4 min read What is the use of append() method in JQuery ? In this article, we are going to see how to use the append() method in jQuery. The append() method is used to insert new content inside an existing element. There are some other methods also that provide to insert new content inside an existing element and these are - prepend(), html(), text(), befo 2 min read Like