• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 21. Cascading Style Sheets and C... > Changing Style Classes On-the-Fly

Changing Style Classes On-the-Fly

In the preceding two examples, we changed individual style attributes. But what if you have dozens of style attributes you’ve set up in a style class?

It turns out that you can change the style class of an element on-the-fly in JavaScript. You might expect that you use a property named class for that to match the HTML CLASS attribute, but the word class is already reserved in JavaScript, so you use a property called className instead. Here’s an example showing how that works. In this case, I’ll change the style class of a <DIV> element from blue to red text when the mouse moves over the element:


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint