W3C home > Mailing lists > Public > www-dom@w3.org > October to December 2000

RE: setAttribute

From: Rob Relyea <rrelyea@microsoft.com>
Date: Fri, 15 Dec 2000 17:39:18 -0800
Message-ID: <DD62C16D92CF434CA50283B8E11F3A3FA05467@red-msg-06.redmond.corp.microsoft.com>
To: "'Peter Benoit'" <pbenoit@triton-network.com>, www-dom@w3.org
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 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:13:48 GMT