W3C home > Mailing lists > Public > public-css-archive@w3.org > June 2016

Re: [csswg-drafts] [selectors] is #42 a valid ID selector?

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
Message-ID: <issue_comment.created-227621429-1466560019-sysbot+gh@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 
 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 

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 
using your GitHub account
Received on Wednesday, 22 June 2016 01:47:04 UTC

This archive was generated by hypermail 2.4.0 : Tuesday, 5 July 2022 06:40:59 UTC