> Yes, but my question was, is it safe for me to be doing x.id,
> x.style ?

For *reflected* attributes like `id` and `className`, and for `style`
which isn't really an attribute (although its values are drawn from an
attribute, they're parsed), yes. Those are consistent cross-browser.
(With regard to `style`, though, note that not all of its property
names or their expected values are consistent across browsers
(opacity, for instance), so you may be better off sticking with
Element#getStyle and Element#setStyle unless you know these waters
well.)

`readAttribute` does a few things to improve cross-browser
compatibility. For instance, although element.className (the
*property*) is consistent across browsers,
element.getAttribute("class") doesn't work on IE, though it should.
You have to use element.getAttribute("className") instead, which isn't
widely supported by other browsers. (There's no reason for it to be
"className" with getAttribute. The reflected property is only called
"className" because "class" is an [unused] reserved word in
Javascript, but when using getAttribute, we pass in a string.) I think
the same thing is true for the "for" attribute on labels (reflected as
"htmlFor").

(For more on what I mean by "reflected", here's the skinny:
http://www.w3.org/TR/html5/infrastructure.html#reflect)

So for the big, well-known reflected properties, you're fine. For just
about any other attribute, use element.readAttribute.

HTH,
--
T.J. Crowder
Independent Software Consultant
tj / crowder software / com
www.crowdersoftware.com


On May 20, 7:52 am, patrick <patrick99...@gmail.com> wrote:
> > I looked at the code and it seems that readAttribute has some extra
> > plumbing for IE but other than that it works basically as you would
> > expect.
>
> Yes, but my question was, is it safe for me to be doing x.id,
> x.style ?
>
> Or is it recommended to use readAttribute to get those values?
>
> -patrick
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Prototype & script.aculo.us" group.
> To post to this group, send email to prototype-scriptacul...@googlegroups.com.
> To unsubscribe from this group, send email to 
> prototype-scriptaculous+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/prototype-scriptaculous?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to