I have a Div with contents
<div id="dv">
<ul><li><a class="html">abcd</a></li></ul>
<ul><li><a class="bold">cdef</a></li></ul>
<ul><li><a class="bold">xyz</a></li></ul>
</div>
I want to display none second and 3rd ul dynamically. How can I do that ?
You can find all the children of the div, hide them, then find the
ulcontaining theliwith class"html"and show thatul:Live Example | Source
What that does:
$("#dv")– Finds the relevant div.children('ul')– Finds its children that areulelements.hide()– Hides them.find('a.html')– Finds anyaelements withinin thoseuls that have class"html".closest('ul')– Gets theulcontaining thataelement.show()– Shows it