In some cases we need to add or remove an attribute to an element and we have only his parent ID then we can get the child element by using parent ID. For example I have a UL element which have many <li> and each <li> has an anchor tag.
<ul id="parentUL">
<li><a></a></li>
<li><a></a></li>
<li><a></a></li>
<li><a></a></li>
</ul>
I want to add a class on very first anchor tag and i have only parent ID. For this i can use this code
$( "#parentUL a" ).first().addClass('active');
0 Comment(s)