jquery click only firing once

前端 未结 3 1972
夕颜
夕颜 2021-01-13 09:07

From looking at other posts I\'ve tried to add live() and on() to my code but the click function only works once and then wont work anymore. Can someone point out what I\'m

3条回答
  •  情歌与酒
    2021-01-13 09:41

    I am assuming (by your code) that the .delete_it item is inside the #step_list element.

    So when you replace its html with the ajax results you remove the bound handlers as well..

    You need to bind the handler to an element up in the DOM hierarchy that does not get removed, for example the #step_list itself..

    So change the binding from

    $(".delete_it").on('click',function() {
    

    to

    $("#step_list").on('click','.delete_it', function() {
    

提交回复
热议问题