如何通过JQuery修改样式属性

How to modify style attribute via JQuery?

本文关键字:样式 属性 修改 JQuery 何通过      更新时间:2023-09-26

我有一些元素,由UI框架生成,如下所示:

<div id="GENERATED_CONTAINER" style="position: fixed; z-index: 100; left: 368px; top: 52px; width: 545px; height: 846px;">
    <div id="GENERATED_CONTENT style="opacity: 0.1; left: 5px; top: 5px; bottom: -5px; width: 545px; height: 846px;">
    </div>
</div>

我需要编写一个脚本,从样式属性中删除widthheight

var elems = $("[id^='GENERATED_']");
//what should I apply now?

只需编写.css

$("[id^='GENERATED_']").css({
  width: 'inherit', //or the value
  height: 'inherit' //or the value
})
$("[id^='GENERATED_']").css({width:0px,height:0px})

您可以使用.css()清除内联样式

以下是通过jQuery.css()添加和删除的内联样式。