O'Reilly logo

Web Programming with HTML5, CSS, and JavaScript by Dean

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

10.11 Manipulating CSS with JavaScript

In this section, we continue to use radio buttons and checkboxes, but our main focus will be on something new and super exciting—using JavaScript to dynamically update a web page’s CSS. There are quite a few JavaScript techniques for manipulating a web page’s CSS. In this section, we show you two such techniques.

Assigning a New Value to an Element’s class Attribute

As you know, you can modify the appearance of an element with the help of the element’s class attribute and a class selector rule. For example, the following code fragment applies italics to a div element by including class="italic" in the div start tag and providing a .italic class selector rule:

<style> .italic {font-style: italic;} .bold ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required