jQuery text() Method

jQuery provide 3 methods to Set or Get the content from a DOM element i.e. text() , html() and val() . These three things might seem like the same thing, but they're not. When these methods are called with no argument, it is referred to as a getters, because it reads (or get) the value of the element. When these methods are called with a value as an argument, it's referred to as a setter because it assign (or sets) that value.

text() - The jQuery text() method is used to set or return the text content of the selected elements. This method gets the combined text contents of all matched elements . The text() method also return the text content of child elements.

Set Contents with text() Method

Get Contents with text() Method

run this source code Try it Yourself

Changing this text to...

Full Source

Difference between val() and text()

jQuery .val() method gets the value of the input element, regardless of type while jQuery .text() gets the innerText (not HTML) of all the matched elements. It is important to note that the .text() will not work on input elements.
 (C) 2021    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About