jquery: get id from class selector

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

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

Some text


        
7条回答
  •  猫巷女王i
    2020-12-23 09:49

    Doh.. If I get you right, it should be as simple as:

    $('.test').click(function() {
      console.log(this.id);
    });
    
    Some text
    Some text
    Some text

    You can just access the id property over the underlaying dom node, within the event handler.

提交回复
热议问题