Search within TutorialsPark

Jquery Element Content


Learn to use jQuery to work with Element Content


jQuery Manipulating Element: Working with Element Content

The jQuery provides a set of methods to work with the content of element.


Table : Methods for Working with Element Content

Method Description
text() To get the combined text contents of all the element in the jQuery object and their descendants.
text(value) To set the content of each element in the jQuery object.
html() To get the HTML contents of the first element in the jQuery object.
html(value) To set the HTML content of each element in the jQuery object.
text(function)
html(function)
To set the text or HTML content using a function.

jQuery Manipulation : Get Combined text using text() Method

The jQuery Method of text() is used to get the combined text content of each system in thbe set of matched elements, including their descendants.

Example: Get Combined text using text() Method

Give it a TRY! » Note: It returns a string containing the combined text content of the matched elements


To Set the Content of Element using text(text) Method

The jQuery methods of text(text) is used to set the content of each element in the set of matched elements to the specified text.

Example: To set the Content of Element using text(text) Method

Give it a TRY! » Note: It returns a string of text to set as the content of each matched element


Using the html() method to Read Element Content

The jQuery method of html() is used to return the content from the first element.

Example: Using the html() method to Read Element Content

Give it a TRY! » Note:It returns a string representation of the HTML entity within the matched element.


To set the Content using html(HTML) method

The jQuery method of html(HTML) is used to set the HTML content of each element in the jQuery Object.

Example: To Set the Content using html(HTML) method

Give it a TRY! » Note:It returns a jQuery Object, which can also be used for Chaining purposes.


Setting properties using a function with text() and html() Method

The jQuery method of text(function) and html(function) is used to insert text and html content using the function.

Example: Setting properties using a function with css(property, function) method

Give it a TRY! » Note: The function is used to insert HTML and text content on matched elements.