我想删除应用于特定 div 的内联和外部 css。
我不想使用 remove_all_styles() 来删除页面的所有样式。
我怎样才能做到这一点?
删除样式和类属性是否有效?
$("#ParticularDiv").removeAttr("class").removeAttr("style");
你可以试试;
$("#div"){
remove_attributes()
}
然后你就会有一张白纸。
您可以通过 $('#div') {remove_atributes()} 将其删除,这将删除 div 中的所有属性,否则您可以使用 remove_class('ClassName') 删除包含样式的类
删除特定 div 的内联 css
$('#div_id').removeAttr('style');
或者你也可以在你的css中使用not
属性来做到这一点。
在 html 中:
<button class="nostyle">
在 CSS 中:
button:not(.nostyle) {
您可以通过div
使用氚选择它然后使用该attribute(...)
功能清除style
属性来做到这一点。假设我有以下 html:
<html>
<body>
<div style="background: red">Hi</div>
</body>
</html>
我可以编写以下氚来删除内联样式:
$("/html/body/div") {
attribute("style", "")
}
一个捷径是使用remove(...)
氚中的函数。借助一些 XPath 魔法,您可以将上面的代码变成一个单行代码,如下所示:
remove("/html/body/div/@style")
这应该删除与 that 相关的内联样式div
。