[英]jQuery.data() with CSS
I change with setAttribute('color', 'black')
the CSS of some element. 我用setAttribute('color', 'black')
更改了某些元素的CSS。 After this element will be stored in a jQuery.data() object. 之后,此元素将存储在jQuery.data()对象中。 But in my data() object the CSS which I defined before won't be stored. 但是在我的data()对象中,我之前定义的CSS将不会存储。
What am I doing wrong? 我究竟做错了什么?
Thanks for the help! 谢谢您的帮助!
If I have: 如果我有:
<div class="element"></div>
With jquery you can do: 使用jquery,您可以执行以下操作:
$(".element").css("color", "black");
This will render the following: 这将呈现以下内容:
<div class="element" style="color:black;"></div>
However using setAttribute will render: 但是,使用setAttribute将呈现:
<div class="element" color="black"></div>
setAttribute
does not alter CSS. setAttribute
不会更改CSS。 It alters attributes. 它更改属性。
If you want to set CSS then you would: 如果要设置CSS,则可以:
element.style.color = 'black';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.