JQuery gets content and attribute methods and examples


Get content-text (), HTML (), and val()

Three simple and useful jQuery methods for DOM manipulation:

Text () - sets or returns the text content of the selected element HTML () - sets or returns the content of the selected element (including HTML markup) Val () - sets or returns the value of the form field

Get attribute -attr ()

The jQuery attr() method is used to get the attribute value.

The following example shows how to get the value of the href attribute in the link:

The instance


$("button").click(function(){
alert($("#w3s").attr("href"));
});