Document.write() - ドキュメントに書き込む
write()は、Documentのメソッドです。open()で開かれている状態のドキュメントに、追加でHTMLを書き込みます。
概要
- 名前
- write
- 所属
- Document
- IDL
[CEReactions] void write(DOMString... text);
- 仕様書
- https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-document-write
説明
HTMLの内容を表す文字列。任意の数だけ引数を指定できる。
チュートリアル
引数は任意の数だけ指定できます。下記は同じ結果になります。
// 1つの引数を指定
document.write( "S" ) ;
document.write( "Y" ) ;
document.write( "N" ) ;
document.write( "C" ) ;
document.write( "E" ) ;
document.write( "R" ) ;
// 複数の引数を指定
document.write( "S", "Y", "N", "C", "E", "R" ) ;
デモ
Document.write()のデモです。
<!-- このコードは編集できます。 -->
<!DOCTYPE html>
<html>
<body>
<script>
document.open() ;
document.write( "<b>Hello!!</b>" ) ;
document.write( "<s>Hello!!</s>", "<i>Hello!!</i>" ) ;
document.close() ;
</script>
</body>
</html>
サポート状況
Chrome | Firefox | Safari | Edge | IE | Opera | iOS Safari | Android |
---|---|---|---|---|---|---|---|
● | ● | ● | ● | ● | ● | ● | ● |
関連記事
- Document.createElement()
- createElement()は、Documentのメソッドです。タグ名を指定して、要素を新しく作成します。
- Selection.addRange()
- addRange()は、Selectionのメソッドです。Rangeを指定して選択範囲をセットします。既に選択範囲が存在する場合、無視されます。
- Selection.type
- typeは、Selectionのプロパティです。選択範囲の種類を文字列で返します。
- Selection.focusNode
- focusNodeは、Selectionのプロパティです。選択範囲の終点を含むノードを返します。