Re: [selectors4] Behavior undefined for multiple elements sharing the same ID

On Mon, Sep 11, 2017 at 8:46 AM, Sangwhan Moon <sangwhan@iki.fi> wrote:

>
> > On 11 Sep 2017, at 3:17 PM, Xidorn Quan <me@upsuper.org> wrote:
> >
> > On Mon, Sep 11, 2017, at 04:04 PM, Sangwhan Moon wrote:
> >> While dealing with a strange edge case related to duplicated IDs
> >> (triggered via cloneNode(), but also can be done by poorly written
> >> markup) I noticed that the selectors spec doesn't define what
> >> implementations are expected to do when there are multiple elements
> which
> >> define the same ID.
> >
> > The spec makes it pretty clear that all elements with the same ID should
> > be
> > matched.
> >
> > The spec says:
> >> An ID selector represents an element instance that has an identifier
> that
> >> matches the identifier in the ID selector.
> > and it specifically mentions the case after:
> >> (It is possible in non-conforming documents for multiple elements to
> match
> >> a single ID selector.)
>
> Oh, I completely missed that statement between the parentheses. Thanks.
>
> I was referring to this bit: "whatever the document language, an ID typed
> attribute can be used to uniquely identify its element." - my confusion
> mostly comes from the fact that unique IDs for conformance is implied in
> HTML at the moment, but is not enforced (and from what I gather, not
> defined either - which makes it a bit unclear if it duplicate IDs is
> against conformance or not.) - I suppose that's something I need to bring
> up with HTML and report back what is actually a conforming document in this
> context.
>

"When specified on HTML elements, the id attribute value must be unique
amongst all the IDs in the element's tree and must contain at least one
character. The value must not contain any ASCII whitespace."

https://html.spec.whatwg.org/multipage/dom.html#the-id-attribute

HTH,

(As a minor nit, all the examples in the same section also imply singular,
> adding to the confusion. :-( )
>
> Sangwhan
>

Received on Monday, 11 September 2017 07:24:17 UTC