- From: Tab Atkins Jr. via GitHub <sysbot+gh@w3.org>
- Date: Wed, 22 Jun 2016 01:47:00 +0000
- To: public-css-archive@w3.org
> Are there fundamental objections to relaxing the ID selector syntax
so that "#" + element.id be always a valid ID selector when working
with an HTML5 document?
Yes, "# + element.id" is *far* wider than [the CSS Syntax spec's
notion of a
`<hash-token>`](https://drafts.csswg.org/css-syntax/#hash-token-diagram),
which is well-established for two decades or so. Extending this to
accommodate basically any character whatsoever would be a significant
change to CSS parsing, and would be pretty weird in the context of
what CSS normally understands as a token. (For example, an ID can
contain the `#` character, or other characters used in Selector
parsing like `.` or `:`.) Basically it would require a hash-token to
be "every character between a # and the next space", which is super
not-compatible.
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 `id="42"`, you can write a selector like `#\34 2` (note
you have to double-escape the slash if writing this in JS, so
`document.querySelector("#\\34 2")`). Is this *convenient*? No, of
course not. But if you want convenience, stick to the generous syntax
that CSS is friendly to.
--
GitHub Notification of comment by tabatkins
Please view or discuss this issue at
https://github.com/w3c/csswg-drafts/issues/202#issuecomment-227621429
using your GitHub account
Received on Wednesday, 22 June 2016 01:47:04 UTC