jquery tools error: Uncaught Error: Syntax error, unrecognized expression: [href=/]

ぐ巨炮叔叔 提交于 2019-12-02 05:08:31

I'm assuming you have a selector that is meant to match elements with an href attribute value of /. You will need to put the / character in quotes:

var elems = $("[href='/']");

Alternatively, you can escape the character:

var elems = $("[href=\\/]");

From the jQuery docs:

If you wish to use any of the meta-characters ( such as !"#$%&'()*+,./:;<=>?@[\]^{|}~` ) as a literal part of a name, you must escape the character with two backslashes: \\.

Here's a working example. Remove the quotes to generate the same error you mention in your question.

My guess is that you changed the order of the libraries. If you want to use JQuery, its lib has to be loaded first to use an additional JQuery-Expansion-Lib. You should change the order in the <head> like this:

<html>
 <head>
  <link rel="stylesheet" type="text/css" href="formate.css"> //CSS always first
  <script src="URL_TO_JQUERY" type="text/javascript"></script> //JQuery first
  <script src="URL_TO_ADDITIONAL_LIB_1" type="text/javascript"></script>
  <script src="URL_TO_ADDITIONAL_LIB_..." type="text/javascript"></script>
  <script src="URL_TO_ADDITIONAL_LIB_n" type="text/javascript"></script>   
 </head>
</html>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!