querySelector on an ID containing a slash errors
Reported by
t...@thomasconroy.net,
Mar 28 2017
|
||
Issue descriptionUserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36 Steps to reproduce the problem: 1. create an element with an id containing a slash 2. perform document.querySelector on the id containing a slash 3. error What is the expected behavior? It should select the element. getElementById() has no problem processing the slash, just querySelector. Per the HTML5 spec, all non-whitespace characters are valid ID's. https://www.w3.org/TR/html5/dom.html#the-id-attribute What went wrong? Browser behavior does not much the CSS spec for valid ID characters. https://www.w3.org/TR/html5/dom.html#the-id-attribute Did this work before? N/A Does this work in other browsers? No other browsers behave similarly to Chrome. Chrome version: 56.0.2924.87 Channel: stable OS Version: OS X 10.11.6 Flash Version: Can we please make the browser behave consistently with the spec? :)
,
Mar 28 2017
You can also use a helper function:
var id = 'hello/world';
document.querySelector('#' + CSS.escape(id))
,
Mar 29 2017
woxxom@ is right. |
||
►
Sign in to add a comment |
||
Comment 1 by woxxom@gmail.com
, Mar 28 2017