Reputation: 331
I would like to select the p elements inside a particular div, #homepage. I know how to select all the #homepage, or all of the li's on the page, but how do I selected a nested group of li's?
Thank you!
Upvotes: 0
Views: 166
Reputation: 1324
$("div#homepage p")
or $("div#homepage>p")
if you need "direct" children of #homepage
.
Upvotes: 0
Reputation: 887225
You can nest selectors by separating them with a space.
In your case, $('#homepage p')
matches all p
elements that are inside (directly or nested) a #homepage
element.
If you only want p
s that are directly inside #homepage
, use a child selector, like this: $('#homepage > p')
.
For more information, read the documentation.
Upvotes: 0
Reputation: 66191
$("#homepage p"); // All the `p` tags inside `div#homepage`
You need to look at the jQuery Documentation for Selectors and specifically the section titled Hierarchy.
Upvotes: 2