Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Some JQuery help please...

Featured Replies

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 :)

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() {

  • Author

unfortunately that didn't make a difference mate :( any other ideas?

 

Ta

  • 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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.