jQuery text()

jQuery text() method can either be used to set text content ( where it overwrites the content of all matched elements) or can be used to return the text content ( where it returns the combined text content of all matched elements without the HTML markup).

jQuery text() sets or returns the text content of selected elements.


When it is used to return text content.


When it is used to set text content.


Content: Content is a compulsory parameter, used to specify the new text content for the selected elements.

When it is used to set text content by calling function.

$(selector).text(function (index, currentcontent))

Function: It is an optional parameter that returns the new text content on calling.

Index: It is passed as an argument inside the function to show the index position of the element.

Current content: This is another argument passed inside the function to show the current text content of the selected element.


<!DOCTYPE html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
$("p").text("Hello! I am back.</b>");
<button>Click me</button>
<p>Bye Bye!</p>
Please follow and like us:
Content Protection by DMCA.com