I'm trying to change the class of a nested span element, when clicking a certain item. JSFiddle goes here.
HTML:
<div id="title_1" class="title">Title 1</div>
<span id="foo_1" class="foo">
foo contents<br />
<span class="bar">bar contents</span>
<br /><br />
</span>
<div id="title_2" class="title">Title 2</div>
<span id="foo_2" class="foo">
foo contents<br />
<span class="bar">bar contents</span>
<br /><br />
</span>
Changing the class of the first span is possible though $(this).nextAll('.foo:first').addClass('highlight'); like I'm doing in the current JSFiddle.
However I want to change the class of 'bar' element only.
Among some things of what I tried:
$(this).nextAll('.foo:first .bar:first').addClass('highlight');
$(this).nextAll('.foo .bar:first').addClass('highlight');
$(this).nextAll('.foo:first').nextAll('.bar:first').addClass('highlight');
$(this).next('.foo').next('.bar').addClass('highlight');
... all without success.
I think I'm missing something basic here. Can someone help me out?