javascript - Toggle button isn`t working?(Uncaught SyntaxError: Unexpected identifier ) -


there problem code. use button hide , show menu isn't working. didn't understand problem.

uncaught syntaxerror: unexpected identifier :: par. 3

$(function() {   $(".but").click( {     if $("#div").hasclass("class"){  //problem here       $("#div").removeclass("class").addclass("anotherclass");     } else{       $("#div").removeclass("anotherclass"").addclass("class");     }   }); });'     

as others have said you're missing function, "but" not valid selector, , added () in if statement, that's coding preference

$(function () {     $("button").click(function () { //but not valid selector, button         if ($("#div").hasclass("class")) { //problem here             $("#div").removeclass("class").addclass("anotherclass");         } else {             $("#div").removeclass("anotherclass").addclass("class");         }     }); }); 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -