Document.createComment()
createComment()
は新たにコメントノードを作成し、返します。
構文
CommentNode = document.createComment(data);
引数
- data
- 文字列で、コメントに追加されるデータを含みます。
例
var docu = new DOMParser().parseFromString('<xml></xml>', 'application/xml');
var comment = docu.createComment('This is a not-so-secret comment in your document');
docu.getElementsByTagName('xml')[0].appendChild(comment);
alert(new XMLSerializer().serializeToString(docu));
// 表示結果: <xml><!--This is a not-so-secret comment in your document--></xml>
仕様書
仕様書 | 状態 | 備考 |
---|---|---|
DOM document.createComment の定義 |
現行の標準 |
ブラウザーの互換性
BCD tables only load in the browser