开发者

Why doesn't $("div[id*='\\|']") work in IE8 or IE9?

开发者 https://www.devze.com 2023-03-28 23:16 出处:网络
Has anyone ever had the experience where IE8 a开发者_运维知识库nd IE9 won\'t work with a jQuery selector where a special character is escaped?

Has anyone ever had the experience where IE8 a开发者_运维知识库nd IE9 won't work with a jQuery selector where a special character is escaped?

This is the div I want to find:

<div id="hello|12345"></div>

And this is the jQuery selector I'm using to find it: $("div[id*='\\|']")

The result is that it doesn't get found, and I have no idea why. It's such a simple selector, and according to http://api.jquery.com/category/selectors/, using \\ is the proper way to escape the |. This of course works fine in Firefox and Chrome.


It works for me in IE 9 as long as I am using a jQuery version after 1.3.2:

http://jsfiddle.net/ZXPyW/

Are you using an old version? If so, can you upgrade?


jQuery uses this regex to parse the value part of an [attr=value] condition. So you cannot use it in id. Anyways it is not be used in the id as per the standard.

(['"]*)(.*?)\3|)\s*\]


The two backslashes were actually unnecessary.

0

精彩评论

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

关注公众号