text() Method


The text() method is used to get or set the text content of HTML elements.

It works only with plain text and ignores HTML tags.

The text() method is commonly used to update messages, labels, and headings dynamically.

This code retrieves the text content of the element.

This sets new text inside the selected element.

The text content updates dynamically when the button is clicked.

text() Method Notes:

  • Works with plain text only
  • Removes existing HTML tags
  • Used for messages and labels
  • Safe for user input display