JQuery Onclick Menu Slide -
i have following menu working:
https://jsfiddle.net/5g111cyx/
but ofcourse amateur version. need code handle div menu's once add or remove menu's automatically, instead of having change code every single time:
$('#1').click(function () { $('#sub2').hide(150); $('#sub3').hide(150); $('#sub1').slidetoggle(150); }); how go in simple, yet effective way?
please use this
$('#1,#2,#3').click(function () { var isactive = $(this).next("div").hasclass('active'); $(".menu").each(function(){ $(this).slideup(150); $(this).removeclass('active') }); if(! isactive ){ $(this).next("div").slidetoggle(150); $(this).next("div").addclass('active'); $(this).siblings().next("div ul").hide(150); } }); updated code
$(document).ready(function () { $('#1,#2,#3').click(function () { var isactive = $(this).next("div").hasclass('active'); $(".menu").each(function(){ $(this).slideup(150).removeclass('active'); }); if(! isactive ){ $(this).next("div").slidetoggle(150).addclass('active'); $(this).siblings().next("div ul").hide(150); } }); });
Comments
Post a Comment