HTMLScriptElement: свойство text
Базовая поддержка Широко доступно
Эта функция хорошо зарекомендовала себя и работает на многих устройствах и версиях браузеров. Она доступна в браузерах с июля 2015 года.
Свойство text интерфейса HTMLScriptElement — это строка, отражающая текстовое содержимое внутри элемента <script>. Оно работает так же, как и свойство Node.textContent.
Оно отражает значение атрибута text элемента <script>.
Значение
Строка.
Примеры
<script id="el" type="text/javascript"> const num = 10; console.log(num); </script>
const el = document.getElementById("el");
console.log(el.text); // Output: "\n const num = 10;\n console.log(num);\n"
console.log(el.textContent); // Output: "\n const num = 10;\n console.log(num);\n"
el.text = "console.log(10);";
console.log(el.text); // Output: "console.log(10);"
console.log(el.textContent); // Output: "console.log(10);"
Спецификации
| Спецификация |
|---|
| HTML # dom-script-text-dev |
Совместимость с браузерами
| Рабочие столы | Мобильные устройства | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox для Android | Opera Android | Safari на iOS | Samsung Internet | WebView Android | |
text |
1 | 12 | 1 | ≤12.1 | 3 | 18 | 4 | ≤12.1 | 1 | 1.0 | 4.4 |
© 2005–2024 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/text