jQuery Get Content and Attributes

Get HTML, Text, and Values.

jQuery Get Content and Attributes

One of the most important parts of jQuery is the possibility to manipulate the DOM.

jQuery contains powerful methods for changing and manipulating HTML elements and attributes.

Get Content - text(), html(), and val()

  • text() - Sets or returns the text content of selected elements
  • html() - Sets or returns the content of selected elements (including HTML markup)
  • val() - Sets or returns the value of form fields

Get Attributes - attr()

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

Example

alert("Text: " + $("#test").text());