← 返回首页
HTMLScriptElement: text プロパティ - Web API | MDN

このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

HTMLScriptElement: text プロパティ

Baseline Widely available *

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

* Some parts of this feature may have varying levels of support.

textHTMLScriptElement インターフェイスのプロパティで、<script> 要素内のテキストコンテンツを反映する文字列です。これは Node.textContent プロパティと同じ方法で動作します。

これは <script> 要素の text 属性を反映したものです。

In this article

文字列です。

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);"

仕様書

Specification
HTML
# dom-script-text-dev

ブラウザーの互換性

Enable JavaScript to view this browser compatibility table.