Pre Exam Test Practice (SSC | Banking | IAS | GATE | State Level | CLAT | Railways | Insurance | Teaching Exams | NDA | Defence | IES |State Exam )

Organizational Research By

Surprising Reserch Topic questions - Question:jQuery -how to Get Content and Attributes?

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

jQuery DOM Manipulation

One very important part of jQuery is the possibility to manipulate the DOM.

jQuery comes with a bunch of DOM related methods that make it easy to access and manipulate elements and attributes.

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

Three simple, but useful, jQuery methods for DOM manipulation are:

  • 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

The following example demonstrates how to get content with the jQuery text() and html() methods:


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


The following example demonstrates how to get the value of an input field with the jQuery val() method:


  alert("Value: " + $("#test").val());


Get Attributes - attr()

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

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



asked Sep 13, 2013 in jquery by rajesh
edited Sep 12, 2013
0 votes

Related Hot Questions

Government Jobs Opening