开发者

uncaught exception: Syntax error, unrecognized expression: [href=example.html] [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

While testing my website in Firebug i get this error when clicking on a menu button:

uncaught exception: Syntax error, unrecognized expression: [开发者_如何学运维href=schedule.html]

I think it goes wrong here because the current class won't apply but the rest works fine.(these aren't the full code)

html:

<nav>
  <ul>
    <li><a class="current" href="index.html">HOME</a></li>
    <li><a href="schedule.html">SCHEDULE</a></li>
  </ul>
</nav>

js:

$("nav a").removeClass("current");
$("nav a[href="+newHash+"]").addClass("current");


This looks like your culprit:

// add single quotes on your selector value 
$("nav a[href='"+newHash+"']").addClass("current");


Since jquery 1.5, quoting attribute values is mandatory. You can quote with single or double quotes:

$("nav a[href='"+newHash+"']").addClass("current");

or

$('nav a[href="'+newHash+'"]').addClass("current");

Quoting was optional in jQuery 1.4 or lower.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜