【发布时间】:2014-05-03 07:41:12
【问题描述】:
我正在向 DOM 动态添加几个具有“data_record”类的 div。
我希望每个人在单击时都变成一种颜色,而其他人则变成白色背景。
这是我在成功添加 data_record 元素后执行此操作的代码...
$(document).on('click', ".data_record", function(event) {
//turn all others white (this DOES NOT work!)
$('.data_record').css('background','#ffffff');
//turn the clicked element a different colour (this DOES work!)
$(this).css('background', '#EDC580');
});
那么我如何通过它们的类来定位动态添加的元素?
谢谢。
【问题讨论】:
-
在这里工作正常jsfiddle.net/QQ52W
标签: jquery dynamic-html