0

我想删除应用于特定 div 的内联和外部 css。

我不想使用 remove_all_styles() 来删除页面的所有样式。

我怎样才能做到这一点?

4

5 回答 5

1

删除样式和类属性是否有效?

$("#ParticularDiv").removeAttr("class").removeAttr("style");
于 2014-02-06T14:53:32.553 回答
1

你可以试试;

$("#div"){
    remove_attributes()
}

然后你就会有一张白纸。

于 2014-04-16T16:07:41.423 回答
0

您可以通过 $('#div') {remove_atributes()} 将其删除,这将删除 div 中的所有属性,否则您可以使用 remove_class('ClassName') 删除包含样式的类

于 2014-12-02T12:05:10.117 回答
0

删除特定 div 的内联 css

$('#div_id').removeAttr('style');

或者你也可以在你的css中使用not属性来做到这一点。

在 html 中:

<button class="nostyle">

在 CSS 中:

button:not(.nostyle) {

丹尼贝克特有用的小提琴

于 2014-02-06T14:52:48.907 回答
0

您可以通过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

于 2014-02-11T10:32:34.407 回答