HTML5, CSS3, and JavaScript Fourth Edition

(Ben Green) #1

CHAPTER 14. JAVASCRIPT AND AJAX 155


14.7 Try It: Change the Class of an Element


If you want to change a whole bunch of styling all at once, one of the easiest
ways is to assign the styling to aclassand then just change the class of the
element.


Here is a JavaScript function we have namedreclassthat usesgetEle-
mentByIdandsetAttributeto change the class of an element. Place it
in your.



Here is a style sheet that defines two classes to be used in our example.
Place it in your.



Here is somecode to change the class of an item. We click on a





Here is an example of how to mark the paragraphs or images. Establish an
ID for the item that will be changed.


This paragraph changes style.

Free download pdf