faqts : Computers : Programming : Languages : JavaScript : DHTML

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

104 of 110 people (95%) answered Yes
Recently 10 of 10 people (100%) answered Yes

Entry

Can I change the class style assigned to an element?
Can I change the style class assigned to an element?

May 27th, 2000 07:28
Rey Nuņez, Steve Claflin, http://www.w3.org/TR/DOM-Level-2/html.html#ID-95362176


Yes, styles can be cascaded. This is basically accomplished by defining 
two (or more) classes in an embedded or linked style sheet, then 
applying the appropriate style class to the element, for example, on an 
onmouseover event.
<span onmouseover="this.className='newclass'" 
onmouseout="this.className='oldclass'">Hello</span>
The DOM Level 2 specifies the usage of "className" for CSS classes in 
scripting, to avoid language conflicts with other platforms, like Java.
Note however that this is currently supported only in IE4+. Though NS6 
supposedly supports this, it can only do one change, meaning you can't 
revert to the previous class after the change.