Document: append() メソッド

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Document.append() メソッドは、一連の Node オブジェクトまたは文字列オブジェクトを、この文書の最後の子の後に挿入します。文字列オブジェクトは等価な Text ノードとして挿入されます。

このメソッドは Document に子要素を追加します。ツリー内の任意の要素に追加するには Element.append() を参照してください。

構文

js
append(param1)
append(param1, param2)
append(param1, param2, /* …, */ paramN)

引数

param1, …, paramN

挿入する一連の Node オブジェクトまたは文字列オブジェクトです。

返値

なし (undefined)。

例外

HierarchyRequestError DOMException

ノードが階層内の指定した点に挿入できない場合に発生します。

ルート要素を文書に追加

既存の HTML 文書に要素を追加しようとすると、<html> 要素が既に存在する場合は HierarchyRequestError DOMException が発生するかもしれません。

js
let html = document.createElement("html");
document.append(html);
// HierarchyRequestError: The operation would yield an incorrect node tree.

既存の要素のない新しい文書を作成した場合、ルート HTML 要素(またはルート SVG 要素)を追加することができます。

js
let doc = new Document();
let html = document.createElement("html");
doc.append(html);

doc.children; // HTMLCollection [<html>]

仕様書

Specification
DOM
# ref-for-dom-parentnode-append①

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
append

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報