--- title: Node slug: Web/API/Node tags: - API - DOM - DOM Reference - Interface - Node - Reference translation_of: Web/API/Node ---
Node はいくつもの DOM API オブジェクトタイプが継承しているインターフェイスで、それらのさまざまなタイプを同じように扱える (同じメソッドのセットを継承する、または同じ方法でテストできる) ようにします。
以下のインターフェイスはすべて、Node からメソッドやプロパティを継承しています: {{domxref("Document")}}, {{domxref("Element")}}, {{domxref("Attr")}}, {{domxref("CharacterData")}} (which {{domxref("Text")}}, {{domxref("Comment")}}, and {{domxref("CDATASection")}} inherit), {{domxref("ProcessingInstruction")}}, {{domxref("DocumentFragment")}}, {{domxref("DocumentType")}}, {{domxref("Notation")}}, {{domxref("Entity")}}, {{domxref("EntityReference")}}
これらのインターフェイスは、そのメソッドやプロパティが妥当でないときは null を返すことがあります。例外を投げることもあります - 例えば、子が存在できないノードタイプに子を追加するとき。
{{InheritanceDiagram}}
親である {{domxref("EventTarget")}} からプロパティを継承します。[1]
'/' までのすべてになります。Node の子が変化すれば自動的に {{domxref("NodeList")}} オブジェクトが更新されることを意味します。null を返します。null を返します。null を返します。Node の名前を持つ {{domxref("DOMString")}} を返します。名前の構造は、ノードの型によって異なります。例えば、{{domxref("HTMLElement")}} は {{domxref("HTMLAudioElement")}} に対して 'audio' というように対応するタグの名前、{{domxref("Text")}} ノードは '#text' という文字列、{{domxref("Document")}} ノードは '#document' という文字列になります。unsigned short を返します。使用できる値:
| 名称 | 値 |
|---|---|
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 |
null を返します。null を返します。null を返します。null を返します。注記: Firefox 3.5 および以前のバージョンでは、このプロパティで HTML 要素のローカル名が大文字でした (XHTML 要素を除く)。以降のバージョンではこのようになりませんので、このプロパティでは HTML および XHTML の両方が小文字になります。{{gecko_minversion_inline("1.9.2")}}
null になります。
注記: Firefox 3.5 および以前のバージョンでは、HTML 要素の名前空間はありません。以降のバージョンでは、HTML 要素は HTML ツリーおよび XML ツリーで https://www.w3.org/1999/xhtml/ 名前空間内に存在します。{{gecko_minversion_inline("1.9.2")}}
null を返します。親である {{domxref("EventTarget")}} からメソッドを継承します。[1]
true、そうでない場合は false である {{jsxref("Boolean")}} を返します。null を返します。複数の接頭辞がある場合の結果は実装依存です。null を返します)。接頭辞として null を与えると、デフォルトの名前空間を返します。次の関数はすべての子ノードを再帰的にループして、それらに対してコールバック関数を呼び出します。(また、親ノード自身に対しても同様に呼び出されます。
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);
parentNode のすべての子ノードと parentNode 自身を再帰的にループして、それらを this オブジェクトとして callbackFunction を実行します。
parentNodeNode Object)callbackFunctionFunction)次の例はボディの中のテキストの内容を console.log に送るものです:
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')}} | 以下のプロパティを削除: attributes、namespaceURI、prefix、localName。以下のメソッドを削除: isSupported()、hasAttributes()、getFeature()、setUserData()、getUserData()。 |
| {{SpecName('DOM3 Core', 'core.html#ID-1950641247', 'Node')}} | {{Spec2('DOM3 Core')}} | {{domxref("Document")}} で insertBefore()、replaceChild()、removeChild()、appendChild() メソッドを呼び出すと、もうひとつの種類のエラー (NOT_SUPPORTED_ERR) を返します。normalize() メソッドを、適切な {{domxref("DOMConfiguration")}} フラグが設定されていれば {{domxref("Text")}} ノードも正規化できるように変更。以下のメソッドを追加: compareDocumentPosition()、isSameNode()、lookupPrefix()、isDefaultNamespace()、lookupNamespaceURI()、isEqualNode()、getFeature()、setUserData()、getUserData()。以下のプロパティを追加: baseURI、textContent。 |
| {{SpecName('DOM2 Core', 'core.html#ID-1950641247', 'Node')}} | {{Spec2('DOM2 Core')}} | ownerDocument プロパティを、{{domxref("DocumentFragment")}} が null も返すように若干変更。以下のプロパティを追加: namespaceURI、prefix、localName。以下のメソッドを追加: normalize()、isSupported()、hasAttributes()。 |
| {{SpecName('DOM1', 'level-one-core.html#ID-1950641247', 'Node')}} | {{Spec2('DOM1')}} | 初期定義 |
{{Compat("api.Node")}}