jquery: get id from class selector

前端 未结 7 1301
离开以前
离开以前 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:40

    As of jQuery 1.6, you could (and some would say should) use .prop instead of .attr

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

    It is discussed further in this post: .prop() vs .attr()

提交回复
热议问题