The text
property sets or gets the contents of the <script> element.
text |
Yes | Yes | Yes | Yes | Yes |
Return the text property.
var v = scriptObject.text
Set the text property.
scriptObject.text=contents
Value | Description |
---|---|
contents | Set the contents of the script |
A String type value representing the contents of the script.
The following code shows how to get the contents of the <script> element.
<!DOCTYPE html>
<html>
<body>
<!--from w w w . j a v a 2 s .co m-->
<script id="myScript">
document.write("Hello World!");
</script>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myScript").text;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: