Javascript Reference - HTML DOM Script text Property








The text property sets or gets the contents of the <script> element.

Browser Support

text Yes Yes Yes Yes Yes

Syntax

Return the text property.

var v = scriptObject.text

Set the text property.

scriptObject.text=contents

Property Values

Value Description
contents Set the contents of the script




Return Value

A String type value representing the contents of the script.

Example

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: