jquery - Show child-items of any ONE top menu-item and hide/slideup child-items of other -


I have a small issue with the menu toggle. Below is a visual reference to the problem. Currently you can see that both the top links are visible. I need a child to see only one top link at any time. If a top link is clicked then the other should slip / hide their child's items.


Enter image details here


JS

  jQuery (document) .ready (function () {jQuery ('menu-item'). Click (function () {var position = JQuery (this) .position (); jQuery ('.sub-menu', this) .slideDown ('slow');});});   

HTML - Sample structure of menus.

  & lt; Ul class = "menu" & gt; & Lt; Li class = "menu-item" id = "544" & gt; & Lt; A href = "#" & gt; Top link a & lt; / A & gt; & Lt; Ul class = "sub-menu" & gt; & Lt; Li class = "menu-item" & gt; & Lt; A href = "#" & gt; A link & lt; / A & gt; & Lt; / Li & gt; & Lt; Li class = "menu-item" & gt; & Lt; A href = "#" & gt; Link two & lt; / A & gt; & Lt; / Li & gt; & Lt; Li class = "menu-object" & gt; & Lt; A href = "#" & gt; Link three & lt; / A & gt; & Lt; / Li & gt; & Lt; / Ul & gt; & Lt; / Li & gt; & Lt; Li class = "menu-item" id = "545" & gt; & Lt; A href = "#" & gt; Top link two & lt; / A & gt; & Lt; Ul class = "sub-menu" & gt; & Lt; Li class = "menu-object" & gt; & Lt; A href = "#" & gt; Link Four & lt; / A & gt; & Lt; / Li & gt; & Lt; Li class = "menu-object" & gt; & Lt; A href = "#" & gt; Link five & lt; / A & gt; & Lt; / Li & gt; & Lt; Li class = "menu-object" & gt; & Lt; A href = "#" & gt; Link Six & lt; / A & gt; & Lt; / Li & gt; & Lt; / Ul & gt; & Lt; / Li & gt;   

I have tried to follow so many similar issues here, but it is very specific for my affairs. I am just learning JS, please help me here. Thank you.

Change the click handler to:

  jQuery (document)) .ready (function () {jQuery ('menu-item'). (Function () {jQuery ('. Menu item .sub-menu'). SlideUp ('Slow'); // SlideUp all submenus for the first time Status = jQuery (this). Composition (); jQuery ('sub-menu', this). Slidedown ('slow');});});    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -