Remove CSS with JavaScript
Sunday, May 7th, 2006***UPDATE: Previous version didn’t work in IE. Ooops. This one does.
I’m working on an accessability panel for this webpage. One aspect of this panel will be to remove CSS styling. I thought someone out there in Googleland will be searching for such a thing for their site so I thought I would publish what I have. It is a pretty simple script, but some people not familiar with scripting might want this too. It only works on CSS, not depreciated HTML, and the rest of the instructions and usage warnings are in the script comments.
Here is a test page to see it in action: CSS Remove Test.
The code is below, but if you rather download it, here you go: cssRemove.js
/*******************************
REMOVE CSS SCRIPT
Filename: cssRemove.js
Author: Bjorn Tipling
Email:
Website: https://sharewonders.com
License: MIT License http://www.opensource.org/licenses/mit-license.php
Instructions:
Add:
inbetween your
tags.Add:
somewhere on your webpage. Click link to remove CSS. Customize as you wish with a class attribute.
IMPORTANT: This only works on CSS. Depreciated HTML tags and attributes such as or border=”1″ will not be removed.
********************************/
function removeStyle(){
var style;
var linkP = document.getElementById(’cssRemoveLink’);
for(i=0;i
void(document.styleSheets.item(i).disabled=true);
}
style = document.getElementsByTagName('*');
for ( i=0; i
void(style[i].style.cssText = '');
}
linkP.innerHTML = "CSS removed.";
return false;
}