Closed
Bug 197019
Opened 21 years ago
Closed 21 years ago
Unabel to set HTMLelement className as defined in DOM level 2
Categories
(Core :: DOM: Core & HTML, defect)
Tracking
()
RESOLVED
INVALID
People
(Reporter: Mats.Gauffin, Assigned: jst)
References
Details
User-Agent: Mozilla/5.0 (Windows; U; WinNT4.0; en-US; rv:1.2.1) Gecko/20021130 Build Identifier: Mozilla/5.0 (Windows; U; WinNT4.0; en-US; rv:1.2.1) Gecko/20021130 Can not set HTMLElement attribute "className" using setAttribute function myHTMLelement.setAttribute("className","myClass"); Using the wrong attribute name "class" sets the "className" attribute myHTMLelement.setAttribute("class","myClass"); the DOM 2 HTMLElement interface I use is http://www.w3.org/TR/2000/WD-DOM-Level-2-HTML-20001113/html.html Reproducible: Always Steps to Reproduce: 1. set class: myHTMLelement.setAttribute("className","myClass"); 2. read class: myHTMLelement.className is not set 3. set class: with myHTMLelement.setAttribute("class","myClass"); 4. read class: myHTMLelement.className is set Actual Results: in step 2 className is not set in step 4 className is set Expected Results: in step 2 className shoud have been set in step 4 className shoud not have been set, it is not a DOM 2 element interface name
Comment 1•21 years ago
|
||
It's either: myHTMLelement.setAttribute("class","myClass"); or myHTMLelement.className = "myClass"; What you're doing is setting the "className" _attribute_, not the "className" DOM property.
Status: UNCONFIRMED → RESOLVED
Closed: 21 years ago
Resolution: --- → INVALID
Reporter | ||
Comment 2•21 years ago
|
||
myHTMLelement.setAttribute is a function defined in DOM level 2 therefore I expect to be able to set "className" using the name defined in that interface, "class" is not defined as an attribute name there. ____________________________________________________________ interface Element : Node { void setAttribute(in DOMString name, in DOMString value) raises(DOMException); ... } interface HTMLElement : Element { ... attribute DOMString className; }; Attributes className of type DOMString The class attribute of the element. This attribute has been renamed due to conflicts with the "class" keyword exposed by many languages. See the class attribute definition in HTML 4.0.
Comment 3•21 years ago
|
||
You're confusing IDL attributes (which are accessible in ECMAScript as properties of the object) and HTML attributes (which are accessible via the getAttribute/setAttribute methods). If you use setAttribute, it sets the _HTML_ attribute. So doing |setAttribute("className", "foo") on a <div> is equivalent to having the HTML <div className="foo">. On the other hand, the |className| property, when set, sets the "class" HTML attribute.
Comment 4•20 years ago
|
||
*** Bug 263235 has been marked as a duplicate of this bug. ***
Comment 5•20 years ago
|
||
*** Bug 263235 has been marked as a duplicate of this bug. ***
You need to log in
before you can comment on or make changes to this bug.
Description
•