[펌글] 자바스크립트 nodeType 에 대하여

By | 10월 28, 2011

- 출처 : https://developer.mozilla.org/en/nodeType -

Summary

Returns an integer code representing the type of the node.

Syntax

var type = node.nodeType;

type is an unsigned short with one of the following values:

  • Node.ELEMENT_NODE == 1
  • Node.ATTRIBUTE_NODE == 2
  • Node.TEXT_NODE == 3
  • Node.CDATA_SECTION_NODE == 4
  • Node.ENTITY_REFERENCE_NODE == 5
  • Node.ENTITY_NODE == 6
  • Node.PROCESSING_INSTRUCTION_NODE == 7
  • Node.COMMENT_NODE == 8
  • Node.DOCUMENT_NODE == 9
  • Node.DOCUMENT_TYPE_NODE == 10
  • Node.DOCUMENT_FRAGMENT_NODE == 11
  • Node.NOTATION_NODE == 12

Example

This example checks if the first node inside the document element is a comment node, and if it is not, displays a message.

var node = document.documentElement.firstChild;
if(node.nodeType != Node.COMMENT_NODE)
  alert("You should comment your code well!");
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments