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

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

Why doesn\'

19条回答
  •  自闭症患者
    2020-11-22 12:19

    $('#test') returns a jQuery object, so you can't use simply object.id to get its Id

    you need to use $('#test').attr('id'), which returns your required ID of the element

    This can also be done as follows ,

    $('#test').get(0).id which is equal to document.getElementById('test').id

提交回复
热议问题