To check if a CSS class exists, in newer browers you can use the document.stylesSheets property for CSS loaded as separate files or as <style ...>, but not inline styles like <div style="attr: value;"
function verifyStyle(selector) {
var rules;
var haveRule = false;
if (typeof document.styleSheets != "undefined") { //is this supported
var cssSheets = document.styleSheets;
outerloop:
for (var i = 0; i < cssSheets.length; i++) {
//using IE or FireFox/Standards Compliant
rules = (typeof cssSheets[i].cssRules != "undefined") ? cssSheets[i].cssRules : cssSheets[i].rules;
for (var j = 0; j < rules.length; j++) {
if (rules[j].selectorText == selector) {
haveRule = true;
break outerloop;
}
}//innerloop
}//outer loop
}//endif
return haveRule;
}//eof
The value for selector should be exactly what is in the CSS including dots #s and spaces
So to verify .className {....}
call the function like
var ok = verifyStyle(".className");
Main Topics
Browse All Topics





by: raj3060Posted on 2006-01-05 at 14:50:39ID: 15624111
You can read the class name :
ame)"/>
<input type="text" class="textbox" onkeyup="alert(this.classN
but I am not too sure if you can figureout if that class exist.