使用jQuery从div中添加和删除样式属性 [英] Adding and removing style attribute from div with jquery
问题描述
我继承了我正在从事的项目,并且正在更新一些jquery动画(jquery的很少实践).
I've inherited a project I'm working on and I'm updating some jquery animations (very little practice with jquery).
我有一个div,我需要从中添加和删除样式属性.这是div:
I have a div I need to add and remove the style attribute from. Here is the div:
<div id='voltaic_holder'>
在动画的某一点上,我需要为其添加一种样式:
At one point in the animation I need to add a style to it:
<div id='voltaic_holder' style='position:absolute;top:-75px'>
我已经搜索了一下,找到了 .removeAttr()
方法,但是我看不到如何添加它,甚至看不到它的远程部分(例如顶部:-75px).
I've searched around and found the .removeAttr()
method but I can't see how to add it, or even remote parts of it (like the top:-75px only).
谢谢
推荐答案
您可以执行以下任何操作
You could do any of the following
分别设置每个样式属性:
Set each style property individually:
$("#voltaic_holder").css("position", "relative");
一次设置多个样式属性:
Set multiple style properties at once:
$("#voltaic_holder").css({"position":"relative", "top":"-75px"});
删除特定样式:
$("#voltaic_holder").css({"top": ""});
// or
$("#voltaic_holder").css("top", "");
删除整个样式属性:
$("#voltaic_holder").removeAttr("style")
这篇关于使用jQuery从div中添加和删除样式属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!