jquery – How do I select only the elements who coincide with the exact path? – Education Career Blog

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>

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.



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

This will select only immediate children


#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.

Leave a Comment