<section id="first">
<h1>Colors</h1>
<section id="red">
<h1>Red</h1>
<section id="apples">
<h1>Apples</h1>
</section>
<section id="apples">
<h1>Strawberries</h1>
</section>
</section>
<section id="orange">
<h1>Orange</h1>
</section>
</section>
$('section').click(function(){
$(this).css('color','yellow');
});
I want the section
s to turn yellow when they are clicked. However, as $('section')
could also refer to their parent elements, it's applying the CSS to them as well.
How can I tell jQuery to apply the CSS to the clicked child element only and not the parent?
I don't want to use $('section section')
because I would also like the parent elements to turn yellow if they are clicked specifically. So I need a JavaScript/jQuery solution, not a selector or HTML solution.