jQuery插件正在应用内联样式(display:block)。我感觉很懒,想用display:none重写它。
最好的(懒惰的)方法是什么?
jQuery插件正在应用内联样式(display:block)。我感觉很懒,想用display:none重写它。
最好的(懒惰的)方法是什么?
当前回答
$('div[style*=block]').removeAttr('style');
其他回答
$("#element").css({display: "none"});
起初,我试图删除css中的内联样式,但它不起作用,新样式如display: none将被覆盖。但在JQuery中,它是这样工作的。
.removeAttr("style")来去掉整个style标签…
.attr("style")来测试值,看看是否存在内联样式…
.attr("style",newValue)将其设置为其他值
$('div[style*=block]').removeAttr('style');
懒惰的方式(这将导致未来的设计师诅咒你的名字,并在你睡觉时谋杀你):
#myelement
{
display: none !important;
}
免责声明:我不提倡这种方法,但它肯定是懒惰的方式。
我有类似的问题与宽度属性。我不能从代码中删除!important,因为它在一个新模板上需要这种样式,我添加了一个Id (modalstyles)到元素中,然后我添加了以下代码到模板中:
<script type="text/javascript">
$('#modalstyling').css('width', ''); //Removal of width !important
$('#modalstyling').width('75%'); //Set custom width
</script>