It is easy to get the attributes of a node. ELEM [attrname] seems to be good,
ELEM. getattribute (attrname );
Since it is so simple, it seems unnecessary to introduce it.
But all evil browsers make such a simple thing very complicated.
The attributes described in this article include the following functions:
Setattribute
Getattribute
Hasattribute
Setstyle
Getstyle
1. getattribute
Getattr is mainly compatible with special attributes, such as href SRC. in IE, you must use getattrbute ('src', 2) to obtain the actual content.
2. setattribute
Setattr is used to set element attributes. Generally, you can directly use the system's setattribute.
3. getstyle
Getstyle is not just a simple way to get the value of the node's style attribute, because some CSS attributes are defined in CSS and these attributes are not obtained in the style attribute. For IE, use
Node. currentstyle gets the current property value. For other browsers, use window. computestyle (node, null); get (2nd parameters are pseudo classes). Almost all frameworks are getstyle at the same time, and the attribute names are overwritten by rules, such as font-size-> fontsize, you can easily obtain CSS with the same name.
Some special attributes cannot be obtained normally (for example, auto). In ie, the unit cannot end with PX. Therefore, jquery deals with this situation. The method is to use runtimestyle. pixelleft and runtimestyle. Left to coordinate the calculation. (See jquery source code)
4. setstyle
Setstyle is the value defined in the style. For numbers, you must manually add 'pxy '.