Let's take a moment to discuss the difference between this versus this wrapped with jQuery. Now, if you have no interest in jQuery, you can feel free to skip this lecture. But I think most front end web developers have worked with jQuery to some extent and probably work with it on a regular basis. It's definitely worth taking a minute to discuss the difference between these two scenarios and some of the problems that you can run into, in your examples folder, open up the context sub folder, and then open the file context this versus this one. So here, I'm iterating over each of the salespeople DOM elements or the list items. And on each iteration of the each method, I'm creating a click event handler.
And in that click event handler, I'm saying this dot hide. So let's first run the code and see what we get. So we're going to show examples and context this versus this one. So now I've run the code. And click the Select button and I get an error. This dot hide is not a function.
All right? What's the problem, we'll see if we can figure it out. So the first thing I want to do is I want to disable or comment on line number five. Since that's throwing an error, it's not really going to help us. And then I'll paste in to console or statements. The first one is I'm expecting the JavaScript, this keyword.
And the second one is I'm expecting the JavaScript this keyword wrapped with jQuery. So let's save that file. And then we'll just refresh the page and click the Select button and I go to console there's statements. Let's look at the first one. The first one is a DOM element. It's a raw JavaScript DOM element.
And the second one is a DOM element wrapped with jQuery. So the difference is the second one is the first one wrapped with jQuery. hope that makes sense. But for the first one, it let's scroll down a little bit and we can see there's a style property and that style property has a display Property display is currently set to an empty string. Okay, so we're going to talk about that in a second. So the short answer is, this is the raw DOM element that's currently being iterated over that was in this case was clicked.
Where is this represents that DOM element wrapped with jQuery. So it's, it's like taking yourself and putting yourself in a coat. It's still you but you're wrapped with a coat. So let's look at it. If you look at the file context, this versus this to, what I'm going to do is say this dot style dot display equals none so if you run context, this versus this too, and then click the Select button you can see the button disappears and if I click other buttons, they used to disappear. Why is that?
Oh if you remember that, we did the console doctor this. We saw that This, this JavaScript keyword, which is a DOM element has a style property and a style property has a display property. And we're just setting it to none. So the point I'm making here is just to illustrate that the JavaScript, this keyword inside of this click event handler, is just a raw DOM element. It's not has nothing to do with jQuery. If we go to contact this versus this three.
Something a little bit different is we're saying this wrapped with jQuery dot style dot display equals none. So let's see how that works. So if we go to show code examples, context, this versus three, and then we click the Select button, we get an error cannot set property display of undefined. And that's because this wrapper jQuery does not have a style property. Remember, it's the JavaScript this keyword or it's the raw DOM element, but it's wrapped with jQuery. So it has different properties and methods.
If you open up context, this versus four The differences now we're seeing this dot height. So if you run context, this versus four, and then select the button, it disappears, and there's no error. And that's because jQuery or this wrapper, jQuery does have a hide method. So the main thing to keep in mind is that the JavaScript, this key word by itself, and kind of inside of a click event handler, is just the raw JavaScript DOM element. And it has a certain set of properties and methods. Where is it this wrapped with jQuery that is a jQuery object.
And it's basically taking this object and wrapping it inside of jQuery, which gives it different properties and methods. So you might be thinking, well, I use jQuery and I use this crap with jQuery. That's fine. Well, there's some situations When jQuery will return this and you think it's going to be this wrapped with jQuery, like when you're creating a jQuery plug in. There's some tricky scenarios. So 99.9% of the time, you'll be dealing with this route with jQuery, and that's all fine.
But two things. One, it's really good to understand the difference and to, it's going to come up, there's going to be a time when you think you're getting one and you're getting the other or you want to convert one to the other. And that's all fine. But you can only go down that road if you really understand the tooth. The difference between these two things