/ Published in: JavaScript
This JavaScript function will dynamically change the style information for any CSS class in a Web Page. Applying this function to a class will cause all items calling on the class to change to the updated style value. This function works even if there are multiple stylesheets referenced in the document.
Example usage (assuming you have a stylesheet defining the "exampleA" class and "exampleB" id:
changecss('.exampleA','display','none'); changecss('#exampleB','display','none');
Expand |
Embed | Plain Text
function changecss(theClass,element,value) { //documentation for this script at http://www.shawnolson.net/a/503/ var cssRules; if (document.all) { cssRules = 'rules'; } else if (document.getElementById) { cssRules = 'cssRules'; } for (var S = 0; S < document.styleSheets.length; S++) { for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) { if (document.styleSheets[S][cssRules][R].selectorText == theClass) { document.styleSheets[S][cssRules][R].style[element] = value; } } } }
You need to login to post a comment.
