我正在向 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');
});
那么如何通过他们的类来定位动态添加的元素呢?
谢谢。