Example of Changing an Element's CSS Class Name with Javascript

Mouse over and out of the paragraph below to change its CSS class


This is a paragraph of text. By default, in the XHTML, the <p> tag has the class attribute set to "class1". There is a mouseover event handler that changes that class name to "class2" when you mouseover the paragraph. There is also a mouseout event handler that changes the class name back to "class1" when you mouse out of the paragraph.

Go on, give it a try.