--- title: Node slug: Web/API/Node tags: - DOM - Node translation_of: Web/API/Node ---
Node
는 여러 가지 DOM 타입들이 상속하는 인터페이스이며 그 다양한 타입들을 비슷하게 처리할 수 있게 한다. 예를들어, 똑같은 메소드를 상속하거나 똑같은 방식으로 테스트를 할수있다
다음의 인터페이스들은 모두 Node
로부터 메소드와 프라퍼티를 상속한다: {{domxref("Document")}}, {{domxref("Element")}}, {{domxref("CharacterData")}} ({{domxref("Text")}}, {{domxref("Comment")}}, {{domxref("CDATASection")}}이 상속), {{domxref("ProcessingInstruction")}}, {{domxref("DocumentFragment")}}, {{domxref("DocumentType")}}, {{domxref("Notation")}}, {{domxref("Entity")}}, {{domxref("EntityReference")}}
이 인터페이스들은 메소드나 프라퍼티가 적합하지 않은 경우에 null을 반환할 수 있다. 그들은 예외를 발생할 수 있다 - 예를 들어 자식이 있을 수 없는 노드 타입에 자식을 추가할 때 말이다.
부모인 {{domxref("EventTarget")}}으로부터 프라퍼티를 상속한다.[1]
'/'
.Node
change, the {{domxref("NodeList")}} object is automatically updated.null
if the node has no child.null
if the node has no child.localName
to be defined on the {{domxref("Element")}} interface, Gecko-based browsers still implement it on the {{domxref("Node")}} interface.null
if it is no namespace. In Firefox 3.5 and earlier, HTML elements are in no namespace. In later versions, HTML elements are in the http://www.w3.org/1999/xhtml
namespace in both HTML and XML trees. {{ gecko_minversion_inline("1.9.2") }}namespaceURI
to be defined on the {{domxref("Element")}} interface, Gecko-based browsers still implement it on the {{domxref("Node")}} interface.null
if there isn't such node.Node
. The structure of the name will differ with the name type. E.g. An {{domxref("HTMLElement")}} will contain the name of the corresponding tag, like 'audio'
for an {{domxref("HTMLAudioElement")}}, a {{domxref("Text")}} node will have the '#text'
string, or a {{domxref("Document")}} node will have the '#document'
string.unsigned short
representing the type of the node. Possible values are:
Name | Value |
---|---|
ELEMENT_NODE |
1 |
ATTRIBUTE_NODE {{deprecated_inline()}} |
2 |
TEXT_NODE |
3 |
CDATA_SECTION_NODE {{deprecated_inline()}} |
4 |
ENTITY_REFERENCE_NODE {{deprecated_inline()}} |
5 |
ENTITY_NODE {{deprecated_inline()}} |
6 |
PROCESSING_INSTRUCTION_NODE |
7 |
COMMENT_NODE |
8 |
DOCUMENT_NODE |
9 |
DOCUMENT_TYPE_NODE |
10 |
DOCUMENT_FRAGMENT_NODE |
11 |
NOTATION_NODE {{deprecated_inline()}} |
12 |
Node
type, this returns null
and any set operation is ignored. For nodes of type TEXT_NODE
({{domxref("Text")}} objects), COMMENT_NODE
({{domxref("Comment")}} objects), and PROCESSING_INSTRUCTION_NODE
({{domxref("ProcessingInstruction")}} objects), the value corresponds to the text data contained in the object.null
.null
.null
.null
if no prefix is specified.prefix
to be defined on the {{domxref("Element")}} interface, Gecko-based browsers still implement it on the {{domxref("Node")}} interface.null
if there isn't such node.부모인 {{domxref("EventTarget")}}으로부터 메소드를 상속한다.[1]
Boolean
flag containing the result of a test whether the DOM implementation implements a specific feature and this feature is supported by the specific node.The following function recursively cycles all child nodes of a node and executes a callback function upon them (and upon the parent node itself).
function DOMComb (oParent, oCallback) { if (oParent.hasChildNodes()) { for (var oNode = oParent.firstChild; oNode; oNode = oNode.nextSibling) { DOMComb(oNode, oCallback); } } oCallback.call(oParent); }
DOMComb(parentNode, callbackFunction);
Recursively cycle all child nodes of parentNode
and parentNode
itself and execute the callbackFunction
upon them as this
objects.
parentNode
Node Object
).callbackFunction
Function
).The following example send to the console.log
the text content of the body:
function printContent () { if (this.nodeValue) { console.log(this.nodeValue); } } onload = function () { DOMComb(document.body, printContent); };
Element.prototype.removeAll = function () { while (this.firstChild) { this.removeChild(this.firstChild); } return this; };
/* ... an alternative to document.body.innerHTML = "" ... */ document.body.removeAll();
명세 | 상태 | 주석 |
---|---|---|
{{SpecName('DOM WHATWG', '#interface-node', 'Node')}} | {{Spec2('DOM WHATWG')}} | Removed the following properties: attributes , namespaceURI , prefix , and localName .Removed the following methods: isSupported() , hasAttributes() , isSameNode() , getFeature() , setUserData() , and getUserData() . |
{{SpecName('DOM3 Core', 'core.html#ID-1950641247', 'Node')}} | {{Spec2('DOM3 Core')}} | The methods insertBefore() , replaceChild() , removeChild() , and appendChild() returns one more kind of error (NOT_SUPPORTED_ERR ) if called on a {{domxref("Document")}}.The normalize() method has been modified so that {{domxref("Text")}} node can also be normalized if the proper {{domxref("DOMConfiguration")}} flag is set.Added the following methods: compareDocumentPosition() , isSameNode() , lookupPrefix() , isDefaultNamespace() , lookupNamespaceURI() , isEqualNode() , getFeature() , setUserData() , and getUserData(). Added the following properties: baseURI and textContent . |
{{SpecName('DOM2 Core', 'core.html#ID-1950641247', 'Node')}} | {{Spec2('DOM2 Core')}} | The ownerDocument property was slightly modified so that {{domxref("DocumentFragment")}} also returns null .Added the following properties: namespaceURI , prefix , and localName .Added the following methods: normalize() , isSupported() and hasAttributes() . |
{{SpecName('DOM1', 'level-one-core.html#ID-1950641247', 'Node')}} | {{Spec2('DOM1')}} | Initial definition. |
{{Compat("api.Node")}}