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
Post a Comment