Tuesday, September 13, 2011

What is the significance of val() method and text() method using jQuery?


The text() method as the name suggests, returns string that contains the text contents of all matched elements. 
This method can be applied for  both HTML and XML documents.


Note : text() cannot  be used for input elements. For input field text , we need to use the val() method.
It is also used to Set the text contents of all matched elements.
$(“#ddlID”).text() – gets  text of all the items inside the dropdown id ddlID
$(“.classdefine”).text() = gets text of all elements with clas classdefine
$("p").text() – gets text inside element Paragraph. It can be same applied to all elements except input text field.

No comments:

Post a Comment