CharacterData: data プロパティ
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.
data
は CharacterData
インターフェイスのプロパティで、現在のオブジェクトのデータの値を表します。
値
この CharacterData
ノードに含まれる文字情報による文字列です。
例
メモ: CharacterData
は抽象インターフェイスです。
以下の例はこれを実装した 2 つの具象インターフェイス、 Text
と Comment
を使用しています。
data を使用したコメントの読み取り
html
<!-- これは HTML のコメントです -->
<output id="result"></output>
js
const comment = document.body.childNodes[1];
const output = document.getElementById("result");
output.value = comment.data;
data を使用してテキストノードの内容を設定
html
<span>結果: </span>未設定
js
const span = document.querySelector("span");
const textnode = span.nextSibling;
textnode.data = "このテキストは 'textnode.data' を使用して設定されました。";
仕様書
Specification |
---|
DOM # dom-characterdata-data |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
関連情報
CharacterData.length
: このCharacterData
ノードに含まれるデータの長さを返す