jQuery 如何使用jQuery删除样式属性下的宽度属性?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7995491/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to remove width attribute which is under style attribute using jQuery?
提问by Fero
<div class="views" style="position: relative; width: 421px; height: 15px; overflow: hidden;">
TEST TEXT
</div>
How to remove width attribute which is under style attribute using jQuery?
如何使用jQuery删除样式属性下的宽度属性?
I know removeAttr("width");
我知道 removeAttr("width");
But it will not work here because width is child of style attribute
但它在这里不起作用,因为宽度是样式属性的子项
回答by Avaq
You could use:
你可以使用:
.css('width', 'auto')
回答by Yuri Ghensev
As easy as
一样容易
$('div.views').css('width', '');
回答by warvariuc
This also worked here:
这也在这里工作:
$(".views").width("");
回答by jrummell
Don't use inline styles. Use classes.
不要使用内联样式。使用类。
$(".views").removeClass("a");
$(".views").addClass("b");
But if you really want to, you could do the following:
但如果你真的想要,你可以执行以下操作:
$(".views").css("width", "");
回答by Akshay Khandelwal
I think you must try this:
我想你必须试试这个:
$(".views").removeAttr('style').attr('style','position: relative; height: 15px; overflow: hidden;');
$(".views").removeAttr('style').attr('style','position: relative; height: 15px; overflow: hidden;');
回答by Jovica ?alovi?
You can do that with CSS only:
你只能用 CSS 做到这一点:
div[style="position: absolute; top: -136px; overflow: auto; width:1241px;"] {
width: 0px !important;
display: none !important;
}
}