Setting Styles with JavaScript

ClassName Swap

To change many style properties at once, switch the className.

document.getElementById("copytext4").className = "blueArea";

The CSS

This is example text in a textarea element, id='copytext4'.

Make a function

Here's how to make it into a function.

function setClassName(objId, className) {
    	document.getElementById(objId).className = className;
}

Call setClassName

Click the 'eval' to have JavaScript evaluate the previous and next text (call the function).

setClassName("copytext4", "copytext");

When setClassName is called, the arguments passed are "copytext4" and "copytext". Looking at the function, the parameter objId will hold the value "copytext4" and the parameter className will hold the value "copytext".

 

*AnimTree
*Tabs
*GlideMenus
*DragLib