.Net Interview Questions and Answers

Search:

Jquery interview questions: - When do we need Document.Readyevent ?

By : Shiv Prasad Koirala | Jun 2nd, 2014 | Views : 4184 | Comments : 0 Bookmark and Share

HTML is loaded in to DOM by the browser in an interpreted manner. In other words every line is read from the HTML code and full finalDOM is created in memory after the last HTML statement is interpreted.



Now take the example of the below Jquery code which is accessing "txt1". At the line where Jquery is calling the textbox , the textbox is not loaded in DOM so this line will crash.


<body>

<script language=javascript>

       $("#txt1").val("Hello Jquery");->Txt1 not loaded in DOM

</script>

<input type="text" id="txt1" />

</body>


This is where "document.ready"Jquery function comes to help and below is how we write it. The "ready" event fires when the complete DOM is loaded in memory. So now the below Jquery script will execute once all elements are loaded and thus will not have issues accessing the text box "txt1".


<script language=javascript>

$(document).ready(

function ()

$("#txt1").val("Hello Jquery");

}

);

</script>


Below is a nice video on Document.Ready from ShivprasadKoirala's site questpond. Below is the youtube link.


 
Rate this Article :
1 Star
2 Stars
3 Stars
4 Stars
5 Stars
1 1 1 2 1
 
 
 
 

.NET interview questions 6th edition (Sixth edition) - By Shivprasad Koirala

In this article we will explain .NET interview questions 6th edition (Sixth edition) - By Shivprasad Koirala.... Read More

What is the difference between Stored Procedures and Function (SQL Server interview question with answers)?

In this article we will explain what is the difference between Stored Procedures and Function.For more articles and videos visit us on www.questpond.com... Read More

Explain MVC application life cycle?

In this article we will explain MVC application life cycle.For more articles and videos visit us on www.questpond.com... Read More

C# Design pattern interview questions with answers: - How Singleton is different from Static class?

In this article we will explain How Singleton is different from Static class.... Read More

WCF interview questions and answers: - What is the difference between Service endpoint and Client endpoint?

In this article we will explain What is the difference between Service endpoint and Client endpoint.... Read More

.NET interview questions 6th edition (Sixth edition) - By Shivprasad Koirala

In this article we will explain .NET interview questions 6th edition (Sixth edition) - By Shivprasad Koirala.... Read More

What is the difference between Stored Procedures and Function (SQL Server interview question with answers)?

In this article we will explain what is the difference between Stored Procedures and Function.For more articles and videos visit us on www.questpond.com... Read More

Explain MVC application life cycle?

In this article we will explain MVC application life cycle.For more articles and videos visit us on www.questpond.com... Read More

C# Design pattern interview questions with answers: - How Singleton is different from Static class?

In this article we will explain How Singleton is different from Static class.... Read More

WCF interview questions and answers: - What is the difference between Service endpoint and Client endpoint?

In this article we will explain What is the difference between Service endpoint and Client endpoint.... Read More

Article Categories

Learn in Hindi