HTMLScriptElement: text プロパティ
Baseline
広く利用可能
*
この機能は広く実装されており、多くのバージョンの端末やブラウザーで動作します。2015年7月以降、すべてのブラウザーで利用可能です。
* この機能の一部は、対応レベルが異なる場合があります。
text は HTMLScriptElement インターフェイスのプロパティで、<script> 要素内のテキストコンテンツを反映する文字列です。これは Node.textContent プロパティと同じ方法で動作します。
これは <script> 要素の text 属性を反映したものです。
値
文字列です。
例
html
<script id="el" type="text/javascript">
const num = 10;
console.log(num);
</script>
js
const el = document.getElementById("el");
console.log(el.text); // 出力: "\n const num = 10;\n console.log(num);\n"
console.log(el.textContent); // 出力: "\n const num = 10;\n console.log(num);\n"
el.text = "console.log(10);";
console.log(el.text); // 出力: "console.log(10);"
console.log(el.textContent); // 出力: "console.log(10);"
仕様書
| 仕様書 |
|---|
| HTML> # dom-script-text-dev> |