this.id vs. $(this).attr('id')

前端 未结 3 680
北海茫月
北海茫月 2020-12-09 07:27

Is

$(this).attr(\'id\') 

the same as:

this.id
3条回答
  •  天命终不由人
    2020-12-09 08:24

    No, they're not exactly the same.

    They'll both return the element's ID, but if the element has no ID, then this.id will return a blank string while $(this).attr("id") will return undefined.

提交回复
热议问题