Chrome は、div の次のプロトタイプ チェーンを提供します。
element = document.getElementById("test")
<div id="test">…</div>
element.__proto__
HTMLDivElement
element.__proto__.__proto__
HTMLElement
element.__proto__.__proto__.__proto__
Element
element.__proto__.__proto__.__proto__.__proto__
Node
element.__proto__.__proto__.__proto__.__proto__.__proto__
Object
element.__proto__.__proto__.__proto__.__proto__.__proto__.__proto__
null
Firefox の場合、以下のようなものが得られ、xpconnect はブリッジのように見えます。Mozilla のドキュメント (Chrome と同じ) で同じプロトタイプ チェーンの画像を取得しました。ここで私の質問は、HTMLDiv 要素からトラバースして Node オブジェクトを取得する方法です。div要素がある場合、NodeオブジェクトまたはHTMLElementのような他のオブジェクトを提供するjsコードを誰かが書くことができますか?
画像はクロムモデルと同じように見えますが、このツリーをトラバースするコードが必要です:)
前もって感謝します。
var element = document.getElementById("test");
element.toString();
[object HTMLDivElement]
element.__proto__.toString();
[xpconnect wrapped native prototype]
element.__proto__.__proto__.toString();
[xpconnect wrapped native prototype]
element.__proto__.__proto__.__proto__.toString();
[xpconnect wrapped native prototype]
element.__proto__.__proto__.__proto__.__proto__.toString();
[object DOM Constructor.prototype]
element.__proto__.__proto__.__proto__.__proto__.__proto__.toString();
[object Object]
私は element.constructor.prototype を信じています。プロトとエレメント。プロトも同じです。