Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Node.nodeType

현재 번역은 완벽하지 않습니다. 한국어로 문서 번역에 동참해주세요.

읽기 전용 프로퍼티인 Node.nodeType은 노드의 타입을 나타냅니다.

Description

nodeType 프로퍼티는 elements, textcomments 처럼 서로 다른 종류의 노드를 구별하는데 사용할 수 있습니다. 

Syntax

var type = node.nodeType;

노드의 타입을 정의한 integer 값을 Return합니다. Node type constants. 이 곳에 값들이 정의되어 있습니다.

Constants

Node type constants

Constant Value Description
Node.ELEMENT_NODE 1 An Element node such as <p> or <div>.
Node.TEXT_NODE 3 The actual Text of Element or Attr.
Node.PROCESSING_INSTRUCTION_NODE 7 A ProcessingInstruction of an XML document such as <?xml-stylesheet ... ?> declaration.
Node.COMMENT_NODE 8 A Comment node.
Node.DOCUMENT_NODE 9 A Document node.
Node.DOCUMENT_TYPE_NODE 10 A DocumentType node e.g. <!DOCTYPE html> for HTML5 documents.
Node.DOCUMENT_FRAGMENT_NODE 11 A DocumentFragment node.

Deprecated node type constants

The following constants have been deprecated and should not be used anymore.

Constant Value Description
Node.ATTRIBUTE_NODE 2 An Attribute of an Element. The element attributes are no longer implementing the Node interface in DOM4 specification.
Node.CDATA_SECTION_NODE 4 A CDATASection. Removed in DOM4 specification.
Node.ENTITY_REFERENCE_NODE 5 An XML Entity Reference node. Removed in DOM4 specification.
Node.ENTITY_NODE 6 An XML <!ENTITY ...> node. Removed in DOM4 specification.
Node.NOTATION_NODE 12 An XML <!NOTATION ...> node. Removed in DOM4 specification.

Examples

Different types of nodes

document.nodeType === Node.DOCUMENT_NODE; // true
document.doctype.nodeType === Node.DOCUMENT_TYPE_NODE; // true

var fragment = document.createDocumentFragment();
fragment.nodeType === Node.DOCUMENT_FRAGMENT_NODE; // true

var p = document.createElement("p");
p.textContent = "Once upon a time...";

p.nodeType === Node.ELEMENT_NODE; // true
p.firstChild.nodeType === Node.TEXT_NODE; // true

Comments

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)
  console.log("You should comment your code well!");

Specifications

Specification Status Comment
DOM
The definition of 'Node.nodeType' in that specification.
Living Standard Deprecated ATTRIBUTE_NODE, CDATA_SECTION_NODE, ENTITY_REFERENCE_NODE and NOTATION_NODE types.
Document Object Model (DOM) Level 3 Core Specification
The definition of 'Node.nodeType' in that specification.
Recommendation No changes.
Document Object Model (DOM) Level 2 Core Specification
The definition of 'Node.nodeType' in that specification.
Recommendation No changes.
Document Object Model (DOM) Level 1 Specification
The definition of 'Node.nodeType' in that specification.
Recommendation Initial definition.

문서 태그 및 공헌자

 이 페이지의 공헌자: incleaf
 최종 변경: incleaf,