Content Manipluation
Content Manipulation
jQuery allows content Manipulation. The methods used for these purposes are html() and text(). When we do not pass parameters in them, they will simply return the content i.e, we will get content. When the content is passed in them as a parameter it will replace it with the original content i.e, the content will be set or changed or replaced.
html():-
html() will set and get the content in the form of HTML which includes both contents and tags.
Syntax:-
Its syntax is:- $(selector).html(content) OR $(selector).html(function(index, currentcontent))
Further Explanation:-
Parameter | Description |
---|---|
content | Required. Specifies the new content for the selected elements. |
function(index,currentcontent) | Optional. Specifies a function that returns the new content for the selected elements
|
text():-
text() will only set and get the content in the form of HTML content and tags will be changed into normal text/content.
Syntax:-
- Its syntax for returning text content is:- $(selector).text()
- Its syntax for setting text content is:- $(selector).text(content)
- Its syntax for setting text bu function is:- $(selector).text(function(index,currentcontent))
Further Explanation:-
Parameter | Description |
---|---|
content | Required. Specifies the new text content for the selected elements |
function(index,currentcontent) | Optional. Specifies a function that returns the new text content for the selected elements
|