Get clicked element using jQuery on event?

后端 未结 4 2123
深忆病人
深忆病人 2020-11-28 04:49

I\'m using the following code to detect when a dynamically generated button is clicked.

$(document).on(\"click\",\".appDetails\", function () {
    alert(\"t         


        
4条回答
  •  情话喂你
    2020-11-28 05:40

    As simple as it can be

    Use $(this) here too

    $(document).on("click",".appDetails", function () {
       var clickedBtnID = $(this).attr('id'); // or var clickedBtnID = this.id
       alert('you clicked on button #' + clickedBtnID);
    });
    

提交回复
热议问题