RE: setAttribute

Since version 4.0 of IE, our getAttribute() implementation has been focused
on OM properties, not the actual html attributes.

So, here are the ways to set a class:

<style>
.bar {color:green}
.foo {color:red}
</style>

<div class=foo id=d1>my div</div>
<script>
divEl = document.getElementById("d1");

//this works in nav6 and ie4 and later
divEl.className = "bar";

//this works in nav6 but not ie
divEl.setAttribute("class","bar");

//this works in ie but not nav6
divEl.setAttribute("className","bar");
</script>

We can consider fixing this in the future, however, most web authors
probably want to use divEl.className until then since it has worked since
IE4 and also works in Nav6.

thx, rob
lead program manager, ie programmability
rrelyea@microsoft.com

-----Original Message-----
From: Peter Benoit [mailto:pbenoit@triton-network.com]
Sent: Thursday, December 14, 2000 11:42 AM
To: www-dom@w3.org
Subject: setAttribute



It seems that Internet Explorer and Netscape have wildly different ways of
using this method.  I would like to know which is correct... or at least
more correct.

As an example, in IE you would set an attribute as such:

x.setAttribute("className","myclass")

but in Netscape you would do something like:

x.setAttribute("class","myclass")


It appears that Netscape works of the string and applies the matching
attribute, whereas Internet Explorer looks for a matching JS method??

I'm confused, please help.  :)


-Peter

Received on Friday, 15 December 2000 21:40:46 UTC