setAttribute Example
Click on a table cell to set a new attribute value in that cell.
The new value will display in the space below the table.
The table demonstrates these attributes:
Case Sensitivity
- Cells 1 and 2 show the difference between uppercase and
lowercase letters in attribute names. In this case, Internet
Explorer interprets bgColor but not
bgcolor.
Property Names
- Cells 3 and 4 show the difference between attribute names
and property names. In this case, Internet Explorer
interprets className but not
class. (This behavior is similar to how Internet
Explorer interprets htmlFor but not
for.) Notice that while the
className attribute is set and the background
color is changed, the bgColor attribute value
is not changed.
Event Handlers
- Cells 5 and 6 set event handlers. To set an event handler in
Internet Explorer, use attachEvent rather than
setAttribute.
Cell 1: attribute = "bgColor" value = "green" |
Cell 2: attribute="bgcolor" value = "green" |
Cell 3: attribute = "className" value = "myClass" |
Cell 4: attribute = "class" value="myClass" |
Cell 5: attachEvent = "onmouseout"
value = "doEvent" (this is a user-defined function) |
Cell 6: attribute = "onmouseout" value = "this.bgColor='green'" |
Click a table cell above to view its modified attributes here.
[Right-click and choose View Source from the shortcut menu.]
© 2007 Microsoft Corporation. All rights reserved. Terms of use.