JQuery bind event after adding element dynamic

后端 未结 3 1434
广开言路
广开言路 2021-01-25 00:10

I have an issue after adding a element dynamically it doesn\'t have the click event, so i have the following:

$(\".myclass > li\").click(function () {
    ...         


        
3条回答
  •  北荒
    北荒 (楼主)
    2021-01-25 00:55

    need to use event delegation to support dynamic elements

    $(".myclass").on('click', '> li' function () {
        ...
    });
    

提交回复
热议问题