[英]Remove class from stylesheet
Is it possible with javascript to remove an entire style from the stylesheet? JavaScript是否有可能从样式表中删除整个样式?
Example, to remove something like this: 例如,删除类似这样的内容:
.somestyle{
bottom: 17px;
position: absolute;
right: 68px;
}
Thanks in advance. 提前致谢。
You are looking for DOM StyleSheet Object Methods removeRule(\\[index\\])
or deleteRule(index)
您正在寻找DOM StyleSheet对象方法
removeRule(\\[index\\])
或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. 我希望这能帮到您。
You can remove class from a html tag, or add a new class and override those properties in css file with "!important" rule. 您可以从html标记中删除类,也可以添加新类并使用“!important”规则覆盖css文件中的那些属性。
.newclass{
bottom: 0px !important;
position: relative !important;
right: 0px !important;
}
Try jQuery . 试试jQuery。
removeAttr
: removeAttr
:
$(function() {
$('.somestyle').removeAttr('class');
});
Remove a class of stylesheet, no. 删除一类样式表,否。
However, with javascript, you can define a new style that does not inherit the sheet style. 但是,使用javascript,您可以定义不继承工作表样式的新样式。
For example: 例如:
position: inherit;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.