Document.body - body要素
bodyは、Documentのプロパティです。ドキュメントのbody要素を返します。
概要
- 名前
- body
- 所属
- Document
- IDL
[CEReactions] attribute HTMLElement? body;
- 仕様書
- https://html.spec.whatwg.org/multipage/dom.html#dom-document-body
説明
body要素を返す。新しいbody要素を代入することもできる。
デモ
Document.bodyのデモです。
<!-- このコードは編集できます。 -->
<!DOCTYPE html>
<html>
<body>
<script>
// 代入
// var body = document.createElement( "body" ) ;
// body.innerHTML = '<p>新しいbody要素</p>' ;
// document.body = body ;
// 取得
var value = document.body ;
console.log( value ) ;
document.body.appendChild( new Text( value ) ) ;
</script>
</body>
</html>
サポート状況
Chrome | Firefox | Safari | Edge | IE | Opera | iOS Safari | Android |
---|---|---|---|---|---|---|---|
● | ● | ● | ● | ● | ● | ● | ● |
関連記事
- Document.getElementsByName()
- getElementsByName()は、Documentのメソッドです。name属性を指定してノードを取得します。
- 要素の位置座標を取得する
- 指定した要素の位置座標を取得します。
- Document.documentElement
- documentElementは、Documentのプロパティです。ドキュメントのルート(最上位)の要素、すなわち、html要素を返します。
- Document.activeElement
- activeElementは、Documentのプロパティです。フォーカス中の要素を返します。フォーカス中の要素がなければbody要素、それもなければhtml要素、それもなければnullを返します。