- From: Tab Atkins Jr. <jackalmage@gmail.com>
- Date: Mon, 4 Nov 2013 17:30:23 -0800
- To: Jirka Kosek <jirka@kosek.cz>
- Cc: www-style list <www-style@w3.org>
On Mon, Nov 4, 2013 at 4:59 AM, Jirka Kosek <jirka@kosek.cz> wrote: > Proposal for extending Selectors Level 4 with possibility to select > attributes > ============================================================================== > > Currently selectors are able to select only elements from a document > tree. However document tree is not consisting only from elements -- > it can contain also attributes and in many markup languages, including > HTML, attributes are conveying information which is as important as > information stored inside element content. Selectors are becoming > universal query language for HTML content (eg. Selectors API, usage in > JS libraries like jQuery, ...) and should thus allow selection of > attributes as well. > > I propose to add new type of simple selector which will allow > selecting attribute nodes in a document tree. > > Proposed syntax is to use @attribute-name syntax, for example: > > img @alt -- select alt attributes on images > > * @alt -- select all title attributes Rather than consuming a new ASCII character, we could just pile this onto pseudo-element syntax: img::attr(alt) ::attr(title) This would also let us stay more consistent if we ever add some mechanism for selecting attributes on something more than literal name, such as prefix or suffix, because we'd have a nice contained syntax segment for syntax. That is, imagine we end up with something like "[prefix(src-)]" for making a selector for attributes starting with "src-". We could similarly do "::attr(prefix(src-))" to actually select the attributes. While @ might work for this if we do this with functions, as I showed here, it wont' if we do more complex syntax. ~TJ
Received on Tuesday, 5 November 2013 01:31:12 UTC