Hello, in this jQuery video, I am going to show you how to access the parent. So we've got code from a previous tutorial, feel free to check that out, which covers, you know, basically filtering children traversing over children, if you aren't doing for a parent element, pretty simple. So what I'm gonna say is I will, what I'm going to do is change, change. I'll actually just get rid of all this. I'll call this one I'll actually just add in all the while, I'll add an ID of Hello. Okay.
I'm gonna say, so I'm going to select the element. So this is the child element that we're selecting for so is with an ID of Hello. Well, capital H, capital H for ID. Yes, there we go. And we're going to say, dot parent. So this has selected its immediate parent dot add class.
Before we even do this, let me show you what it looks like. So you can see this is div one. And now what? Well there we go. Okay, so if I do dot add class, I've got a classical read here. I'm just gonna add that class and run it.
This class has been applied to the pyramid parent, which also gets applied to the child. What happened is this is in a whole nother class as well. I mean, a whole nother animal. Again, I have to be Dave's are just like you didn't do really simple but it could be anything you want. So if I say tables or reload Think it only applies to the immediate parent, not the other parents. But what you can do is reload.
Commonplaces or I will come in. If I change parent parents, and I reload, it trickle all the way up, and he will affect all parent elements. And if I were to just add some code outside, like Hello, for example. He literally goes all the way up to the root element. That's how you use parents and parents. You can also use an optional parameter, basically filter search for your, you know, the parents, the ancestors, you can apply that into here, this could be a class, this could be an element, I want you to do that.
So you say, you know, only these Tiger parents aren't going to apply this class or do whatever you want. It was an extra task for you. If you have any questions, feel free to pop me a message. And as usual, I look forward to seeing you in the next awesome video.