tags:

views:

32

answers:

2

I use the following expression to select all the links in this "path":

$J('#leftmenu li div a")

The problem is that inside i can have the following hierarchy:

<ul id="lefmenu">
<li><div><a href="#">foo</a>
<ul><li><div><a href="#">subfoo</a>
</li>/ul>
</li>
</ul>

Using this expression this selects foo and subfoo.

I would like the way to select only foo, that is to say the exact path I write in my expression, right now this is selecting all the "li div a", inside the list, that is why it selects foo and subfoo.

+1  A: 

Use

$J("#leftmenu > li > div > a")

This will select only immediate children

Joel Potter
A: 
#leftmenu > li > div > a

See the documentation for more information on what selectors are available. They are based on CSS selectors, so documentation on those should help too.

Brian Campbell
You should probably link to the jquery selectors page instead.
cletus
@cletus Edited to include link to JQuery docs as well. I think it's important to emphasize, though, that they are based on CSS selectors, so knowledge of one should transfer to the other (though depending on the browser, different sets of selectors may be available).
Brian Campbell