jQuery插件正在应用内联样式(display:block)。我感觉很懒,想用display:none重写它。

最好的(懒惰的)方法是什么?


当前回答

$('div[style*=block]').removeAttr('style');

其他回答

.removeAttr("style")来去掉整个style标签…

.attr("style")来测试值,看看是否存在内联样式…

.attr("style",newValue)将其设置为其他值

如果你想在一个样式属性中删除一个属性——而不仅仅是将它设置为其他属性——你可以使用removeProperty()方法:

document.getElementById('element').style.removeProperty('display');

更新: 我做了一个交互式的小提琴来玩不同的方法和他们的结果。显然,set to empty string、set to faux value和removeProperty()之间没有太大区别。它们都会导致相同的回退——要么是预先给定的CSS规则,要么是浏览器的默认值。

下面是我编写的插入jQuery的inlineStyle选择器过滤器。

$("div:inlineStyle(display:block)") // will select all divs with an inline style of display: block set

在你的例子中,你可以这样使用:

$("div:inlineStyle(display:block)").hide();

美元el.css ({ 高度:", 'margin-top': " });

等等……

只需要保留第二个参数为空!

将插件更改为不再应用该样式。这比随后删除样式要好得多。