What type of DOM Element?

前端 未结 6 1493
一个人的身影
一个人的身影 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:13

    $('#mydiv').get(0).nodeType if you know there's only one element. The selector object can contain an array of objects.

    .get() returns the array of DOM objects, the parameter indexes. nodeType is a property exposed by the DOM that tells you what the type of the DOM node is. Usually as a String in all caps IIRC.

    CORRECTION nodeType gives you an INT corresponding to a nodeType. tagName is what you want.

提交回复
热议问题