Document: body プロパティ
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since May 2018.
値
例
js
// HTML の内容:
alert(document.body.id); // "oldBodyElement"
const aNewBodyElement = document.createElement("body");
aNewBodyElement.id = "newBodyElement";
document.body = aNewBodyElement;
alert(document.body.id); // "newBodyElement"
メモ
document.body
は文書の内容を持つ要素です。 の内容を持つ文書では
要素を返し、フレームセット文書では、これは最も外側の
要素を返します。
body
プロパティは設定が可能ですが、文書に新しい本文を設定すると、既存の 要素の子ノードは全て削除されます。
仕様書
Specification |
---|
HTML # dom-document-body-dev |