I have an iframe with a nested unordered list inside. I want to find the nested ul that has a class of ‘expanded’ and change it to ‘collapsed’.
<iframe id='Catalog'>
<html>
<body>
<ul id='items'>
<li><ul></ul></li>
<li><ul class='expanded'></ul></li>
<li><ul></ul></li>
</ul>
</body>
</html>
</iframe>
I have tried many things, but have not quite gotten it right.
Here is a sample of what I’m trying to get:
$('iframe#Catalog')
.contents()
.find('ul#items li ul')
.hasClass('expanded')
.removeClass('expanded')
.addClass('collapsed');
Thanks in advance!
hasClassreturns a boolean value, it doesn’t filter the elements, you can use class selector instead.