【发布时间】:2012-02-01 15:14:13
【问题描述】:
我有一个 html 元素,它的样式(使用 jquery)具有通过其类名定位的背景图像。
当我删除课程时,背景图像仍然存在 - 这不是我所期望或想要的。
test.html
<div id='log' class='tile'>HELLOWORLD</div>
test.css
.tile{
background: none;
}
test.js
$('.tile').css("background-image", "url(tile.jpg)"); // We see image
$('#log').toggleClass('tile'); // We still see image
在敲了我的头之后,我想我知道发生了什么事。 css 被应用于元素 - 而不是“类”。
如何定位特定的 css 规则以更新其键值?
如果这有意义的话。
【问题讨论】:
-
当使用
toggleClass('tile')时,您将tile添加到现有类中
标签: javascript jquery html css