Getting sender in jQuery

后端 未结 2 500
猫巷女王i
猫巷女王i 2021-01-07 16:41

I have a large list of check boxes all with unique id values. I\'d like to get the id of the checkbox that executes my JavaScript function. Can I d

2条回答
  •  难免孤独
    2021-01-07 17:13

    If this points to your checkbox, then you would get the id using $(this).attr('id')

    For example:

    $('input:checkbox').click(function(){
        var id = $(this).attr('id');
        // do something with id
    });
    

    See DEMO.

提交回复
热议问题