Problem:-
<div>
<div>
<div>
<select id="s1">
.................
</div>
<div>
</div>
I want to toggle the first div, starting from element s1. I can do in this manner:-
$('#s1').parent().parent().parent().toggle(false);
But is there any way i can get to the parent div directly with some shortcut. Is there any way i can avoid using parent() method 3 times ?
Pls suggest.
Try the following:
This will give you the topmost parent div of your select element.
Alternatively there’s the parentsUntil method, which can be used like so: