I'm trying to write some helper functions so I can edit a css class through javascript. Here is what I have, but I don't understand why it keeps returning "undefined". Im using chrome for testing.
function getRule(name, doDelete) { //takes a rule name and boolean
if(document.styleSheets) { //check if there are stylesheets
for(var i = 0; i < document.styleSheets.length; i++) { //loop through style sheets
var currentSheet = document.styleSheets[i];
if(currentSheet.cssRules) { //if the sheet has rules
for(var h = 0; h < currentSheet.cssRules.length; h++) { //loop through css rules
var currentRule = currentSheet.cssRules[h];
if(currentRule.selectorText == name) { //if rule name is equal to the name given
return currentRule; //return the css rule
}
}
}
}
}
}
css being used:
.menuopen {
margin-left: auto;
margin-right: auto;
text-align: center;
font-size: 20px;
width: 960px;
height: 200px;
background-color: 3b7ea8;
box-shadow: inset 0px 2px 5px 3px rgba(0,0,0,0.75);
-webkit-animation-name: dropAnimation;
-webkit-animation-duration: 2s;
}