Closed Bug 263235 Opened 20 years ago Closed 20 years ago

element.setAttribute('className','value') differs from element.className='value'

Categories

(Core :: DOM: CSS Object Model, defect)

x86
Windows 2000
defect
Not set
normal

Tracking

()

VERIFIED DUPLICATE of bug 197019

People

(Reporter: jescribn, Unassigned)

Details

User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; H010818; .NET CLR 1.1.4322) Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; rv:1.7.3) Gecko/20040913 Firefox/0.10.1 element.setAttribute('className','abc') does not update the appearance of an object to match class style 'abc', even though element.className's value has been changed to 'abc'. However, using element.className='abc' does update the appearance. Both versions work in Internet Explorer. I believe both are valid implementations. Example code: <style> .red {color:#ff0000;} .green {color:#00ff00;} .blue {color:#0000ff;} </style> <div id="a" class="red">Text</div><br /> <a href="#" onClick="document.getElementById('a').setAttribute ('className','blue')">getElementbyID('a').setAttribute('className','blue') </a><br> <a href="#" onClick="document.getElementById ('a').className='green'">getElementbyID('a').className='green'</a><br> Reproducible: Always Steps to Reproduce: 1.Run the code above in mozilla or firefox 2.Click the option for blue, note that the class is not visually updated. 3.Click the option for green, note that the class is visually updated. Actual Results: Results described in the steps above. Expected Results: The browser should have visually updated the class in both circumstances.
The attribute is called "class", not "className". change: getElementbyID('a').setAttribute('className','blue') to: getElementbyID('a').setAttribute('class','blue') and it works as expected. So I'm pretty sure this is INVALID. Reporter- please comment if you disagree.
*** This bug has been marked as a duplicate of 197019 ***
Status: UNCONFIRMED → RESOLVED
Closed: 20 years ago
Resolution: --- → DUPLICATE
Referenced DOM HTML L2 Using "class" instead of "className" produces the correct functionality, however "class" is not the valid name for this attribute. According to DOM HTML L2 "className" is used because class "collides with class definitions naming conventions." It was "className" in DOM L1, too. URL: http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109/html.html#ID-58190037 Tnx.
Status: RESOLVED → UNCONFIRMED
Resolution: DUPLICATE → ---
Read 197019 in more detail - understand point. *** This bug has been marked as a duplicate of 197019 ***
Status: UNCONFIRMED → RESOLVED
Closed: 20 years ago20 years ago
Resolution: --- → DUPLICATE
v
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.