Now in order to change the text of a selected element using JQuery, there's two ways of going about 1
this. 2
One is you can simply, say, select an element, then .text, and inside the parentheses you'll add the 3
new text that you want it to say, 4
so this will change our hello to a goodbye. 5
As we mentioned before, when we use jQuery to select an HTML element, it selects all of the elements 6
that match that selector on your web page. 7
So if we were to say .text on the buttons, then when we refresh our page, you can see that every single 8
button gets its text updated by simply selecting for all the elements that match this criteria, 9
and then we're using the .text method to change the text that's inside those buttons, which is this 10
part here. 11
Now, if you remember, when we learnt how to do this using plain old vanilla Javascript, we also had something 12
called innerHTML. And using innerHTML, 13
we were able to not just update text but we were also able to add HTML. But, as we’re using jQuery, it's 14
a little bit shorter. 15
So it's simply .html. And inside here we can add some tags, say for example if we wanted to add the 16
em tag to make our text emphasized, or rather italicised. 17
Now when we update our web site you can see that the HTML is also taken into consideration, because we're 18
using the .html method instead of simply the .text method which will interpret everything in between 19
the quotation marks as pure text and ignores all of the HTML tags. 20
Now by this point you would have noticed that most of the things that you do with jQuery are implemented 21
using methods, and we’re accessing it through the dot notation. 22
Now remember how, when we were learning about methods and functions, 23
we used it a lot to shorten our code and reduce repetition. 24
Well this is pretty much how jQuery works. 25
If you take a look at the library then you'll notice that jQuery is completely written in Javascript, 26
but it has all of these methods that shorten the code that we need to write and makes working with Javascript 27
to create our web sites much much quicker, much easier, and reduces repetitive strain injury from typing 28
so much. 29
So I hope that you also realize that without understanding how vanilla Javascript works, then jQuery 30
just seems like complete magic. 31
So it's really important that you needed to get a good foundation in Javascript before we started introducing 32
you to essentially what most web developers will use when they're writing Javascript, which is doing 33
it through jQuery or another library. 34
I hope that by this point you've already realized that this library can make your life as a developer 35
so much easier with less things to type and more intuitive syntax. 36
But in the next lesson we're going to dig into jQuery even further and we're going to learn how 37
we can manipulate attributes using jQuery. 38
So for all of that, stay tuned. 39
I'll see you on the next lesson.