I'm currently doing some DOM traversal with jQuery, I'm trying to select each element one at a time in #treeList
when button is clicked, but once it goes through the second list #innerList
, it will select all elements in that list, and continue on down the list on click. How can you continue through #innerList
like it does with #treeList
?
$("#MoveDown").click(function() {
$('.parentStyle + li, li:eq(0)')
.last()
.addClass('parentStyle').siblings('li')
.removeClass('parentStyle');
});
.parentStyle {
background-color: #F99;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<ul id="treeList">
<li class="parent">Aunt Grace</li>
<li class="parent">Mother Joan</li>
<li class="parent">Father Joe
<ul id="innerList">
<li class="child">Son John</li>
<li class="child">Son James</li>
<li class="child">Daughter Aine</li>
</ul>
</li>
<li class="parent">Uncle Tom</li>
<li class="parent">Aunt Jen</li>
</ul>
</div>
<button id="MoveDown">Move down</button>