我想通過我在jQuery中添加的類名稱來定位一個元素。這似乎工作正常,如果我添加一個新的元素,但我不能讓新事件綁定到已經在DOM中,但已被更改的元素。如何在文檔準備好後添加通過類名添加的元素?
我在做什麼錯?
$(document).ready(function(){
$(".activateRow").on("click",function(){
$(this).text('Deactivate').addClass('deactivateRow btn-danger').removeClass('activateRow btn-success');
$(this).parent().parent().removeClass('inactiveRow');
});
$(".deactivateRow").on("click",function(){
$(this).text('Activate').removeClass('deactivateRow btn-danger').addClass('activateRow btn-success');
$(this).parent().parent().addClass('inactiveRow');
});
})
謝謝。只要SO讓我接受就會接受。 – erfling