jquery - Click toggle function disabling preventdefault -
i'm trying execute script toggles between 2 functions when touchmenubutton clicked. when it's clicked want add together , remove class, , when it's clicked 1 time again reverse , remove , add together classes. it's not working , can't figure out why.
$(function () { var touchmenubutton = $("#touchmenubutton"); var touchmenucanvas = $("#touchmenucanvas"); var touchmenudrawer = $("#touchmenudrawer"); $(touchmenubutton).click(function (e) { e.preventdefault(); }); $(touchmenubutton).on("click", function () { if $(touchmenucanvas).hasclass("canvas-closed") { $(this).removeclass("canvas-closed"); $(this).addclass("canvas-open"); } else { $(this).removeclass("canvas-open"); $(this).addclass("canvas-closed"); } }); });
you don't have if'ing. toggle classes:
touchmenubutton.click(function(e) { e.preventdefault(); touchmenucanvas).toggleclass("canvas-closed canvas-open"); }); that said, code should work. can't more without more info or demo.
jquery toggle
No comments:
Post a Comment