What is a proper way to add listeners to new elements after using AJAX to get the html content? (jQuery, Javascript)

前端 未结 5 820
谎友^
谎友^ 2021-01-05 09:13

I am making something that can loads new setting pages via AJAX, I am not sure what\'s the most efficient way to bind listeners to those elements from the new content page?<

5条回答
  •  死守一世寂寞
    2021-01-05 09:36

    $(".parent-div").on("click", ".child-div-class-name" ,function(){
      somefunction();
    });
    

    all the new inserted elements inside the .parent-div will be having the listeners onclick

提交回复
热议问题