Intro
To understand how to manipulate text with jQuery, let's start with the basics. Everything in jQuery that relates to text is done with, that's right, you guessed it. The text method.
So for starters, how would you use jQuery to see any text that an element might already contain. Well, with jQuery, it's easy. All you have to do is call an empty text method.
Let's say we have the following HTML element:
- <h1>I am a Heading Tag</h1>
- $("h1") . text();
And if we wanted to change the text, all we have to do is supply some new text for the text method:
- $("h1") . text("This is the new text");