setAttribute Method | Internet Development Index |
Sets the value of the specified attribute.
Syntax
object.setAttribute(sName, vValue [, iFlags])
Parameters
sName Required. String that specifies the name of the attribute. vValue Required. Variant that specifies the string, number, or Boolean to assign to the attribute. iFlags Optional. Integer that specifies one the following flags:
0 When the attribute is set, it overwrites any attributes with the same name, regardless of their case. 1 Default. The case of the attribute that you set is respected when it is set on the object.
Return Value
No return value.
Remarks
If the specified attribute is not already present, the setAttribute method adds the attribute to the object and sets the value.
Be careful when spelling attribute names. If you set iFlags to 1 and the sName parameter does not have the same uppercase and lowercase letters as the attribute, a new attribute is created for the object.
If two or more attributes have the same name, differing only in case, and iFlags is set to 0, this method assigns values only to the first attribute created with this name. All other attributes of the same name are ignored.
When setting the CLASS attribute using this method, set the sName to be "className", which is the corresponding Dynamic HTML (DHTML) property.
Standards Information
This method is defined in World Wide Web Consortium (W3C) Document Object Model (DOM) Level 1 .
Applies To
A, ADDRESS, APPLET, AREA, B, BASE, BASEFONT, BGSOUND, BIG, BLOCKQUOTE, BODY, BR, BUTTON, CAPTION, CENTER, CITE, CODE, COL, COLGROUP, COMMENT, currentStyle, CUSTOM, DD, DFN, DIR, DIV, DL, DT, EM, EMBED, FIELDSET, FONT, FORM, FRAME, FRAMESET, HEAD, hn, HR, HTML, I, IFRAME, IMG, INPUT type=button, INPUT type=checkbox, INPUT type=file, INPUT type=hidden, INPUT type=image, INPUT type=password, INPUT type=radio, INPUT type=reset, INPUT type=submit, INPUT type=text, KBD, LABEL, LEGEND, LI, LINK, LISTING, MAP, MARQUEE, MENU, META, nextID, NOBR, OBJECT, OL, OPTION, P, PLAINTEXT, PRE, runtimeStyle, S, SAMP, SCRIPT, SELECT, SMALL, SPAN, STRIKE, STRONG, style, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TFOOT, TH, THEAD, TITLE, TR, TT, U, UL, userProfile, VAR, WBR, XMP
See Also
getAttribute, removeAttribute