简体   繁体   English

如何通过JQuery修改样式属性?

[英]How to modify style attribute via JQuery?

I have elements, generated by UI-framework as follows: 我有一些由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>

I need to write a script which is to remove width and height from style attributes. 我需要编写一个从样式属性中删除widthheight的脚本。

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

Simply write .css 只需编写.css

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

You can clear the inline style using .css() 您可以使用.css()清除内联样式

Here's a fiddle of inline style being added and removed via jQuery.css() . 这是通过jQuery.css()添加和删​​除的内联样式的小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM