How can I get the ID of an element using jQuery?

后端 未结 19 2590
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 11:57

Why doesn\'

19条回答
  •  北海茫月
    2020-11-22 12:29

    If you want to get an ID of an element, let's say by a class selector, when an event (in this case click event) was fired on that specific element, then the following will do the job:

     $('.your-selector').click(function(){
           var id = $(this).attr('id');
     });
    

提交回复
热议问题