I am trying to run down a UL set:
<ul>
<li>
<h2>Header 1</h2>
<ul class="collapse">
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
<li>E</li>
</ul>
</li>
<li>
<h2>Header 2</h2>
<ul class="collapse">
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
<li>
<h2>Header 3</h2>
<ul class="collapse">
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
<li>
<h2>Header 4</h2>
<ul class="collapse open">
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
<li>E</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
Where if I find one of the children with the class open I want to remove the class collapse and/or open from any parent level UL's prior to that child found with open. Maybe I'm to tired, but I have this seriously flawed logic, in my head I am trying to make sense of it, at the same time I feel its not logical, and theres bound to be an easier way to do this. (Mind you the $.each() I am currently attempting is flawed and doesnt work anyway). But I could use some ideas how to approach this if anyones go some.
$('ul').each(function()
{
if($(':not(:first)', this))
{
if($(this).hasClass('collapse'))
{
alert('collapse found');
$kid = $(this).child('ul');
if($kid.hasClass('open'))
{
alert('uh')
$kid.parents('ul').removeClass('collapse');
}
}
}
});