Skip to content Skip to sidebar Skip to footer

Jquery 1.7.1 Seemingly Can't Handle Html5 Element Ids

As you may be aware, HTML5 allows more characters to be used in ID names - see the HTML5 spec which now has space as the only invalid character. Attempting to use this with JQuery

Solution 1:

Escape the slash (demo: http://jsfiddle.net/m9NT8/):

console.log(​$(document).find('div#foo\\/bar')​​​​)​

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

This behaviour is defined in a RegEx at Sizzle's source code, line 374:

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

Post a Comment for "Jquery 1.7.1 Seemingly Can't Handle Html5 Element Ids"