What is the use of Document.ready in Jquery ? ( ASP.NET Jquery interview questions with answers)
Do not forget to visit www.questpond.com for more such ASP.NET and jquery interview questions with answer videos.
"Document.Ready" event occurs once the complete HTML DOM is loaded. So the next question is when do we actually need this event?.Consider the below simple code where we are trying to set a text box "text1" with value "Sometext".
Now at the point when Jquery code tries set the textbox value , at that moment that text box is not available in the HTML DOM. So it throws an exception for the same.
So we would like to execute the Jquery code which sets the textbox value only when all the HTML objects are loaded in DOM. So you can replace the code of setting text box value to something as shown below.