javascript - Toggle/Show one defined DIV with JS -


i have fiddle you: http://jsfiddle.net/vss4f/

i want show div.sub-menu simple click on a.haschildren. if body loads div.sub-menu should closed. if click second time on a.haschildren div.sub-menu should close.

i have sampled many things think problems lot of div's. 1 idea in fiddle.

$(function()   {     $("a.haschildren").click(function(e) {         e.preventdefault();         $('div.sub-menu:visible').hide();         $(this).next('div.sub-menu').show();     }); }); 

i hope can me, thanks!

try

$(function()   {     $("a.haschildren").click(function(e) {          e.preventdefault();         var item = $(this).closest('div.haschildren').next().next('div.sub-menu').toggle();         $('div.sub-menu:visible').not(item).hide();     }); }); 

demo: fiddle


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -