Get Content and Attributes in jQuery

December 31, 2014 , , , , 0 Comments

Getting and assigning content of elements in jQuery is very simple because of its in-built functions. JQuery provides many in-built functions that can be used to get content of any element and can set html part for any element.

JQuery library contains many DOM related functions that make it easy to use and understand how it is working. Programmer can easily manipulate content of any element or attributes by using existing functions. In rare chances programmer have to write its own functions with collection of JQuery library functions.

To get content of any element on the web-page, programmer can use following three mostly used functions:
  • val(): get or set the value of forms field.
  • text(): get or set the text content of selected elements.
  • html(): get of set the whole content of selected elements including html markup.
Lookout the following example through which we will use all three types of functions and show the values returns by them.


All the above alert messages will return respective values for selected label. The below code fragment will assign some values to all three labels:


In the next article we will get and set attribute's value for an element on the web-page.

Subhash Sharma

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google