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 ...
Get Web Programming with HTML5, CSS, and JavaScript now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.