DOM Node
Nodeインターフェイスは、他の多くのDOM APIオブジェクトのベースとなる抽象的な基底クラスです。抽象クラスであるため、単なるNodeオブジェクトというものは存在しません。Document内にあるすべてのオブジェクトは何らかの種類のNodeです。
Documentはツリーとして表現されます。
次のようなHtml Documentは:
<!DOCTYPE html>
<html class=e>
<head><title>Aliens?</title></head>
<body>Why yes.</body>
</html>
次のように表現される:
HTML構文解析器(HTML parsing)の仕組みから、すべてのASCII whitespaceがText nodesにされていませんが、一般概念は明らかだと思います。 入力のマークアップから、ノードたちが成すツリーが出来上がります。
プロパティ
- Node.baseURI : USVString (readonly)
DocumentのBase urlを返す
- Node.childNodes : NodeList(readonly)
すべての子孫 (要素、テキスト、コメント) を返す
- Node.firstChild : Node(readonly)
最初の子ノードを返す
- Node.isConnected:boolean(readonly)
接続されているか否かを返す
- Node.lastChild : Node(readonly)
最後の子ノードを返す
- Node.nextSibling : Node(readonly)
次のsiblingを返す
- Node.nodeName : DOMString(readonly)
ノードのタイプに適した文字列を返す
- Node.nodeType : unsigned short(readonly)
ノードの型を表すunsigned shortを返す
- Node.nodeValue : DOMString
ノードの値を返す
- Node.ownerDocument : Document(readonly)
ノードが所属するDocumentを返す
- Node.parentNode(readonly) : Node
親ノードを返す
- Node.parentElement : Element(readonly)
親のElementを返す
- Node.previousSibling : Node(readonly)
前のsiblingを返す
- Node.textContent : DOMString
テキストの内容を取得または設定する
これらのプロパティに加え、 Nodeの親であるEventTargetからプロパティを継承しています。
メソッド
- Node.appendChild(node)
末っ子として追加する
- Node.cloneNode(deep)
クローン。deep=trueの場合、子も複製する
- Node.compareDocumentPosition(otherNode)
otherNodeの位置を比較し、結果となるビットマスクを返す
- Node.contains(otherNode)
otheNodeが子孫であるか否か
- Node.getRootNode(options)
rootを返す。optionsが{composed:true}の場合、shadowも含むrootを返す
- Node.hasChildNodes()
子ノードを持っているか否か
- Node.insertBefore(node,child)
現在のノードの子の前にNodeを挿入する(childの兄)
- Node.isDefaultNamespace(namespace)
namespaceがデフォルトの名前空間か否か
- Node.isEqualNode(otherNode)
otherNodeが同値か否か
- Node.isSameNode()
otherNodeが同じか否か
- Node.lookupPrefix(namespace)
namespaceのprefixを調べる
- Node.lookupNamespaceURI(prefix)
prefixの名前空間を調べる
- Node.normalize()
ノーマライズする
- Node.removeChild(child)
childを削除する
- Node.replaceChild(node,child)
nodeでchildを置き換える
これらのメソッドに加え、 Nodeの親であるEventTargetからメソッドを継承しています。
参考リンク