JQuery 1.7.1 doesn't seem to be able to handle HTML5 element identifiers

As you know, HTML5 allows you to use more characters in name names - see the HTML5 specification , which now holds as the only invalid character. Attempting to use this with jQuery shows that jQuery ignores all characters in the ID after a certain valid character, '/'.

<section> <div id='foo/bar'> YAAY </div> <div id='foo'> BOO </div> </section> โ€‹ 

Writing the element 'foo / bar'

 console.log(โ€‹$(document).find('div#foo/bar')โ€‹โ€‹โ€‹โ€‹)โ€‹ 

Shows an invalid return item:

 [ <div id=โ€‹"foo">โ€‹ BOO โ€‹</div>โ€‹ ] 

This uses both stable jQuery (1.7.1) and the current edge of jQuery.

Is this a jQuery bug, or am I doing something wrong?

+4
source share
1 answer

Escape Slash (demo: http://jsfiddle.net/m9NT8/ ):

 console.log(โ€‹$(document).find('div#foo\\/bar')โ€‹โ€‹โ€‹โ€‹)โ€‹ 

PS. $(document).find('selector') equivalent to $(selector) .

This behavior is defined in RegEx in Sizzle Source Code, line 374 :

 ID: /#((?:[\w\u00c0-\uFFFF\-]|\\.)+)/, 
+4
source

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


All Articles