How to create click event for specific link in a jQuery listview.

后端 未结 6 508
北荒
北荒 2020-12-07 06:08

I\'m trying to create a function that starts when you click on a specific link in a listview. The issue is that event doesn\'t seem to fire when you click the link. The lis

6条回答
  •  情歌与酒
    2020-12-07 06:39

    You have to do event delegation for dynamically added elements.

        $('"#listviewForLastTenCalls"').on("click",'li' ,function(){
           alert('triggered');
        });
    

    And why on() works ??

    Event handlers are bound only to the currently selected elements; they must exist on the page at the time your code makes the call to .on().

提交回复
热议问题