On May 7, 10:10 pm, RobG <[EMAIL PROTECTED]> wrote:
> On May 8, 12:52 am, Andrew Dupont <[EMAIL PROTECTED]> wrote:
>
> > Element#readAttribute is meant to work the way the native
> > Element#getAttribute _ought_ to.
>
> The term "native" does not help me here: when you say "ought to", are
> you referring to the DOM 2 Core specification or the actual behaviour
> in various implementations?
I am referring to the spec. Element#readAttribute implements the
spec's definition of Element#getAttribute.
>
> > The DOM spec says getAttribute should
> > always return the string value of the attribute.
>
> Which infers (to me) that getAttribute('disabled') should return
> "true" if the disabled attribute is present in the markup and "null"
> if it isn't. If it has been set by script, it should return "true" or
> "false".
No, it should return "disabled" if the disabled attribute is present
and set to "disabled". Otherwise it should return "". You've got
Element#hasAttribute if you want to check for the attribute's presence
altogether.
(This is a drawback of the prescribed behavior, by the way — there's
no way to distinguish between "<input disabled="" />" and
"<input>" (attribute not present vs. attribute explicitly set to the
empty string).)
We're following the XHTML behavior here, not HTML, because the former
is a sane subset of the latter.
> When setting the value in the markup, there are differences in
> browsers. Firefox seems to think HTML should be treated as XML -
> getAttribute returns 'disabled' only if the attribute is set using
> disabled="disabled", but results in the bizare situation where setting
> disabled="enabled" (or "false" any value you like) disables the
> control but getAttribute returns the literal value (i.e. "enabled" or
> "false" or whatever).
Yeah, that's crazy and stupid and a browser bug.
> [snip]
>
> Reading the property directly is at least
> consistent in a wide variety of browsers, does not require any
> additional code and can be used directly in conditional statements:
>
> if (el.disabled) {...}
>
> seems much clearer to me (and much less prone to error) than:
>
> if (el.readAttribute('disabled') === 'disabled') {...}
>
I agree completely. The former is better. This is an edge case, but
it's worth fixing anyway.
> > Element#readAttribute aims for the consistent behavior
> > across browsers that getAttribute lacks.
>
> Some may infer that consistency means returning values like "enabled",
> "unchecked" and so on.
>
> Have you considered including the selected attribute in the list of
> those supported by readAttribute?.
I haven't, but this isn't my area of expertise. Care to do some
research for us? ;-)
Cheers,
Andrew
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---