Reputation: 1032
Is it possible with javascript to remove an entire style from the stylesheet?
Example, to remove something like this:
.somestyle{
bottom: 17px;
position: absolute;
right: 68px;
}
Thanks in advance.
Upvotes: 1
Views: 1414
Reputation: 22643
You are looking for DOM StyleSheet Object Methods removeRule(\[index\])
or deleteRule(index)
console.log(document.styleSheets);
document.styleSheets[0].deleteRule(0);
console.log(document.styleSheets);
so in your case you can do something like this
var sheetRef =document.styleSheets[0];/*index of the sheet in the markup head el*/
for (i=0; i<sheetRef.rules.length; i++){
if (sheetRef.rules[i].selectorText==".somestyle")
sheetRef.removeRule(i)
}
i hope this will help you.
Upvotes: 1
Reputation: 156
Remove a class of stylesheet, no.
However, with javascript, you can define a new style that does not inherit the sheet style.
For example:
position: inherit;
Upvotes: 0
Reputation: 4686
Try jQuery .removeAttr
:
$(function() {
$('.somestyle').removeAttr('class');
});
Upvotes: 0
Reputation: 12862
You can remove class from a html tag, or add a new class and override those properties in css file with "!important" rule.
.newclass{
bottom: 0px !important;
position: relative !important;
right: 0px !important;
}
Upvotes: 0