How to get the name of an element with Javascript?

后端 未结 5 634
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-20 01:16

I\'m trying to get the name of an element in Javascript. Meaning if the element is

, then \"div\" would be returned. If it\'s &l
5条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-20 01:43

    Use nodeName (see this note about tagName):

    "My advice is not to use tagName at all. nodeName contains all functionalities of tagName, plus a few more. Therefore nodeName is always the better choice."

提交回复
热议问题