Seems simple enough and I think I've done it before once or twice. What is the jQuery selector syntax for grabbing all the <li>
elements inside a <div>
with id "chapters"?
I can get the <li>
elements with $('li')
and the div with $('#chapters')
but I need to limit the selection to <li>
within that div.
Here is the markup, followed by the jQuery selector. It doesn't work and now I'm at a loss as to why:
<li>1 - outside the div</li>
<div id="chapters">
<li>One</li>
<li>Two</li>
<li>Three</li>
</div>
<li>2 - outside the div</li>
JQuery selector:
$('#chapters li').css("background-color","red");
It is simply
$('#chapters li')
Have a look at the selectors documentation.
I think you need to use Period(.
) instead of (#
) in the selector. Below is the code:
$('.chapters li').css("background-color","red");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With