Dynamic style: Manipulating CSS with JavaScript Examples

Note: Some of the example code shown below is not the full code being executed. To make things as simple as possible I wanted to just show the critical code pertaining to style manipulation, thus the code that deals with browser differences is not shown. To see the full code one can view the source code.


Style Sheet Properties example

This example demonstrates how to access the properties of the style sheets.

This text should be larger

This text should be green

CSS Code

<style id="disable_example">
	.hidden {
		display: none;
	}
	.bigger {
		font-size: 150%;
	}
	.green {
		color: green;
	}
</style>
			

JavaScript Code

function disableSheet() {
	document.getElementById('disable_example').disabled=true;
}
function enableSheet() {
	document.getElementById('disable_example').disabled=false;
}