jQuery click event not working after adding class

前端 未结 7 1615
臣服心动
臣服心动 2020-11-22 01:47

In my JSP page I added some links:

Organization Data


        
7条回答
  •  误落风尘
    2020-11-22 02:37

    Based on @Arun P Johny this is how you do it for an input:

    
    

    This is how I got it in jQuery:

    $(document).on('click', "input.btEdit", function () {
        var id = this.id;
        console.log(id);
    });
    

    This will log on the console: myButton1. As @Arun said you need to add the event dinamically, but in my case you don't need to call the parent first.

    UPDATE

    Though it would be better to say:

    $(document).on('click', "input.btEdit", function () {
        var id = $(this).id;
        console.log(id);
    });
    

    Since this is JQuery's syntax, even though both will work.

提交回复
热议问题