HTML DOM Script text Property
The HTML DOM Script text Property is used to set or return the content of the <script> element.
Syntax:
- It Returns the text property:
scriptObject.text
- It is used to set the text property:
scriptObject.text = contents
Property Values: It contains the value i.e contents that specify the content of the <script> element.
Return Values: It returns a string value that represents the content of the script element. i.e. all the Text nodes of the script but ignore the comments.
Example 1: This Example is used to return the text Property.
HTML
<!DOCTYPE html> < html > < head > < title > DOM script text Property </ title > </ head > < body style = "text-align:center;" > < h1 > w3wiki </ h1 > < h2 > DOM script Text property </ h2 > < script id = "myBeginner" type = "text/javascript" > document.write("Hello w3wiki"); </ script > < br > < br > < button onclick = "Beginner()" > Submit </ button > < h2 id = "demo" ></ h2 > < script > function Beginner() { let x = document.getElementById("myBeginner").text; document.getElementById("demo").innerHTML = x; } </ script > </ body > </ html > |
Output:
Example 2: This Example is used to set the text Property.
HTML
<!DOCTYPE html> < html > < head > < title > DOM script text Property </ title > </ head > < body style = "text-align:center;" > < h1 > w3wiki </ h1 > < h2 > DOM script Text property </ h2 > < script id = "myBeginner" type = "text/javascript" > document.write("Hello w3wiki"); </ script > < br > < br > < button onclick = "Beginner()" > Submit </ button > < h2 id = "demo" ></ h2 > < script > function Beginner() { let x = document.getElementById( "myBeginner").text = "Script Content will be changed now"; document.getElementById("demo").innerHTML = x; } </ script > </ body > </ html > |
Output:
Supported Browsers: The browsers supported by HTML | DOM Script text Property are listed below:
- Google Chrome 1 and above
- Edge 12 and above
- Internet Explorer
- Firefox 1 and above
- Apple Safari
- Opera