tags:

views:

59

answers:

5

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!

+2  A: 
$("#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.

Doug Neiner
+2  A: 

All you need to do is:

$('#homepage p')
seth
A: 

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 ps that are directly inside #homepage, use a child selector, like this: $('#homepage > p').

For more information, read the documentation.

SLaks
A: 

$("div#homepage p") or $("div#homepage>p") if you need "direct" children of #homepage.

Lloyd
A: 

For a nested group of li's

$("#homepage li li");
gilmae