-
Notifications
You must be signed in to change notification settings - Fork 715
[selectors] is #42 a valid ID selector? #202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It's just something I accidentally dropped when converting the grammar. Fixed now (with a prose requirement below the main grammar). |
Shouldn't the CSS and HTML specs agree on the form of an ID? To quote from the current draft (https://github.com/w3c/html/blob/master/sections/dom.include):
I understand that one spec talks about the form of ID attribute values and the other spec defines the ID selector syntax, and these are two different things. And I understand that you can escape the ID EDIT: the correct escape syntax is "#\34\32" and this does indeed work in Chrome and Firefox. However, developers routinely use simple string operations to build selectors from attribute values. To be safe, assuming the above is true, they would have to always try and escape ID attribute values if they start with a digit. But no one ever does that, or is aware they need to. jQuery and Sprint actually check the form of the selector, and have a partial workaround. If the selector matches
But this doesn't work for:
because they don't recognize it. Admittedly, ".test" is redundant if IDs are unique in the document, but the point remains that building selectors with string operations is much more complicated if one needs to care whether we're handling ID values or not. With the following document, with non-unique IDs:
jQuery is actually able to successfully execute
Sprint (a jQuery alternative) is not that sophisticated and fails. If Element had a Are there fundamental objections to relaxing the ID selector syntax so that |
Yes, "# + element.id" is far wider than the CSS Syntax spec's notion of a You can still select any ID you want in CSS, you just have to escape it to match the grammar. In particular, if you want to match an element with |
Revise simple iteration progress when an interval is clipped
https://drafts.csswg.org/selectors/#id-selectors says:
But in the grammar
<id-selector>
is defined as<hash-token>
which would appear to allow a sequence beginning with numbers.The text was updated successfully, but these errors were encountered: