On Sep 5, 2:40 am, "Aaron Heimlich" <[EMAIL PROTECTED]> wrote:
> On 9/5/07, Pops <[EMAIL PROTECTED]> wrote:
>
>
>
> > Yes, $('#foobar') returns the 1st one, but you can have as many
> > id="foobar" your applications needs and use this to find them all:
>
> While that's technically true, IDs are meant to be unique to a page. For
> what you're describing, using CSS classes is more appropriate, e.g.
>
> $(".foobar")
No, I am not describing CSS.
In practice, element ids are meant to be unique for practical
purposes but there is no standard restriction that it there SHOULD NOT
be more than one defined. It is an implementation issue. Strictly
speaking W3C DOM standards does not defined that the first element
MUST be returned with getElementById. In fact, it specifically says
"undefined" behavior leaving it open for implementations.
http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-getElBId
"getElementById introduced in DOM Level 2
Returns the Element that has an ID attribute with the given value. If
no such element exists, this returns null. If more than one element
has an ID attribute with that value, what is returned is undefined.The
DOM implementation is expected to use the attribute Attr.isId to
determine if an attribute is of type ID.
Note: Attributes with the name "ID" or "id" are not of type ID
unless so defined.
Parameters
elementId of type DOMString
The unique id value for an element.
Return Value
Element
The matching element or null if there is none."
In practice, when it comes to the element attributes and HTML design,
there is really only one attribute that MUST be unique for a properly
operating design - FORM field names simply because its serialization
depends on it.
Now does jQuery enforce uniqueness for ids? Sure to make it work
right. But it can work fine too when there are more than one similar
ids.
--
HLS