jquery: get id from class selector

前端 未结 7 1321
离开以前
离开以前 2020-12-23 09:22

Is there any way that I can get the id of an element from something like:

Some text


        
7条回答
  •  無奈伤痛
    2020-12-23 09:34

    When you add a click event, this returns the element that has been clicked. So you can just use this.id;

    $(".test").click(function(){
       alert(this.id); 
    });
    

    Example: http://jsfiddle.net/jonathon/rfbrp/

提交回复
热议问题