JQuery addClass SyntaxError: Unexpected token illegal -
what's wrong jquery code? in chromium browser, "uncaught syntaxerror: unexpected token illegal" in using jquery addclass. in advance.
<!doctype html> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script> $(document).ready(function(){ var url = window.location.href; $('ul.menu li').each(function() { var $this = $(this); var suburl = $this.find('a').attr('href'); if(url.indexof(suburl) > 0) { $this.addclass("active"); // **uncaught syntaxerror: unexpected token illegal** //alert("url=" + url + ", suburl=" + suburl); } }); $("button").click(function(){ $("ul.nav a.active").hide(); }); }); </script> </head> <body> <div> <p>list<p> <ul class="menu"> <li><a href="/test/jq_test.html">coffee</a></li> <li><a href="/test/jq_test1.html">milk</a></li> <li><a href="/test/jq_test2.html">tea</a></li> </ul> </div> <button>click me</button> </body> </html>
you have illegal character after ;
copy notepadd++ , see it
if(url.indexof(suburl) > 0) { $this.addclass("active");? // <-- delete //alert("url=" + url + ", suburl=" + suburl); } });
delete , should work
Comments
Post a Comment