Sharon
Sharon

Reputation: 331

jquery selectors

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

Answers (5)

gilmae
gilmae

Reputation: 1

For a nested group of li's

$("#homepage li li");

Upvotes: 0

Lloyd
Lloyd

Reputation: 1324

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

Upvotes: 0

SLaks
SLaks

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

For more information, read the documentation.

Upvotes: 0

seth
seth

Reputation: 701

All you need to do is:

$('#homepage p')

Upvotes: 2

Doug Neiner
Doug Neiner

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

Related Questions