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>) Quote 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 Quote 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 Quote 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)") Quote Link to comment https://forums.phpfreaks.com/topic/265026-selector-help/#findComment-1358246 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.