What type of DOM Element?

前端 未结 6 1495
一个人的身影
一个人的身影 2020-12-14 14:34
e.g. if i have this:
whatever

then let say in jQuery, how can I find out that the dom element with id \"mydiv\"

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-14 15:21

    The .prop() function is a nice way of doing this.

    // Very jQuery
    $('#mydiv').prop('tagName');
    
    // Less jQuery
    $('#mydiv')[0].tagName;
    

    Both give the same result.

    And, as Aram Kocharyan commented, you'll probably want to standardise it with .toLowerCase().

提交回复
热议问题