jquery - finding the name of the element I have a reference to

前端 未结 3 1465
[愿得一人]
[愿得一人] 2021-01-22 01:13

In code I have a reference to a DOM element, in Jquery. How do I find out it\'s id? It maybe counter-intuitive, but I need to know that so I can do some manipulations on another

相关标签:
3条回答
  • 2021-01-22 01:25

    If you have a reference to a DOM element, you can simply access the ID with this.id or element.id.

    Here is a list of properties, HTMLElements have.

    0 讨论(0)
  • 2021-01-22 01:33

    If you want the id then you can use

    $("youelementselector").attr("id");
    

    and if you want elements name then

    $("youelementselector").attr("name");
    

    See attr

    0 讨论(0)
  • $(this).attr("id")
    
    0 讨论(0)
提交回复
热议问题