What is the use of Document.ready in Jquery ? ( ASP.NET Jquery interview questions with answers)
- By Shiv Prasad Koirala in ASP.NET
- Sep 17th, 2013
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.
$("#text1").val("Sometext"); // Throws exception as the textbox is not //accessible at this moment
<input type="text" id="text1" />
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.
Shiv Prasad Koirala
Visit us @ www.questpond.com or call us at 022-66752917... read more