May 7, 201016 yr hi guys, I am coding a little site, mainly to learn more JQ - but I am stumped fairly early on lol. I have a little menu as such: <ul id="subnav"> <li id="work1"> <a href="#">Work 1</a> <ul> <li id="website"> <a href="mypage1.html">My Website</a> </li> <li id="intranet"> <a href="mypage2.html">My Intranet</a> </li> </ul> </li> <li id="work2"> <a href="#">Work 2</a> <ul> <li id="blog"> <a href="mypage3.html">My Website</a> </li> <li id="forum"> <a href="mypage4.html">My Intranet</a> </li> </ul> </li> </ul> *NOTE There are actually loads of categories, not just two Now basically, what should happen is the user clicks on one of the categories, it should open up the sub-menu below it. I have that working at the moment using JQuery: $(document).ready(function() { $("#subnav > li").toggle(function() { $(this).children().addClass("show"); }, function(){ $(this).children().removeClass("show"); }); }); My problem comes when I want to click through to mypage1.html and so on... because it is a child of #subnav > li, it is causing the toggle to close and no click through lol - How do I tell JQUERY to ignore all sub-sub nav's *confused* Cheers
May 7, 201016 yr To select the parent items only: you can use the "has" selector to select <li> items that "have" a <ul> within them. E.g: $("#subnav > li:has(ul)").toggle(function() {
May 8, 201016 yr Author I don't think it is an issue with this line: $("#subnav > li").toggle(function() { I think it is more to do with the fact that the nav is set up in such a way that the UL with all of the individual pieces of work is WITHIN the LI tag that toggles the menu... does that make sense? I think I need to find a way of using the <A> tag to set off the toggle, but that would mean changing the $(this).children().addClass("show"); Line to something else - ideas on a postcard please
Create an account or sign in to comment