Samuz Posted June 30, 2012 Share Posted June 30, 2012 Let's say I have markup along the lines of.. <ul> <li> <a href="">bla bla</a> <ul> <li><a href="">more bla bla></li> <li><a href="">more bla bla></li> </ul> </li> </ul> And then I do something along the lines of.. $('ul li a').click(function() { // stuff }); How do I select only the primary link (<a href="">bla bla</a>) and ignore the nested links within (<a href="">more bla bla>) Link to comment https://forums.phpfreaks.com/topic/265026-selector-help/ Share on other sites More sharing options...
requinix Posted June 30, 2012 Share Posted June 30, 2012 I don't remember what it's actually called but use that one operator that selects only immediate children. ul > li > a Link to comment https://forums.phpfreaks.com/topic/265026-selector-help/#findComment-1358098 Share on other sites More sharing options...
Samuz Posted June 30, 2012 Author Share Posted June 30, 2012 I don't remember what it's actually called but use that one operator that selects only immediate children. ul > li > a Thanks. Funnily enough I tried that earlier, seems I had to apply it to the container to make it work Link to comment https://forums.phpfreaks.com/topic/265026-selector-help/#findComment-1358102 Share on other sites More sharing options...
haku Posted July 1, 2012 Share Posted July 1, 2012 You can also use: $("a:not(ul li a)") Link to comment https://forums.phpfreaks.com/topic/265026-selector-help/#findComment-1358246 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.