Why is the slash character causing my selector to fail?

Using jQuery 1.6.4 in IE 11

I have an element with a slash in its id.

<span id='a/b'>
test
</span>

In my code I do

alert($('#a/b').length);

The output is 0. This only happens when I have a slash (/) in the ID. document.getElementById ('a / b') is working correctly.

So, I'm confused by why a slash id doesn't work in jQuery?

+4
source share
1 answer

This is not a problem with IE.

This is because it /is a metacharacter, and you cannot use it directly. You should avoid it when using.

http://api.jquery.com/category/selectors/

(, !"#$%&'()*+,./:;<=>?@[\]^``{|}~) , : \.

, id="foo.bar" $("#foo\\.bar").

+1

Source: https://habr.com/ru/post/1681819/


All Articles