
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
HTML DOM Script Object
The DOM Script Object represent the <script> element of an HTML document.
Create script object
Syntax
Following is the syntax −
document.createElement(“SCRIPT”);
Properties of script object
Property |
Explanation |
---|---|
async |
It returns and alter whether the script should be executed asynchronously or not. |
charset |
It returns and modify the value of the charset attribute of a script element in an HTML document. |
defer |
It returns and modify the value of the src attribute of a script element in an HTML document. |
src |
It returns and modify whether the script should be executed when the page has finished parsing. |
crossOrigin |
It returns and modify the CORS setting of a script in an HTML document. |
text |
It returns and modify the text of all the text nodes that are children of a script in an HTML document. |
type |
It returns and modify the value of the type attribute of a script element in an HTML document. |
Example
Let us see an example of script object −
<!DOCTYPE html> <html> <head> <style> body{ text-align:center; background-color:#fff; color:#0197F6; } h1{ color:#23CE6B; } .drop-down{ width:35%; border:2px solid #fff; font-weight:bold; padding:8px; } .btn{ background-color:#fff; border:1.5px dashed #0197F6; height:2rem; border-radius:2px; width:60%; margin:2rem auto; display:block; color:#0197F6; outline:none; cursor:pointer; } </style> </head> <body> <h1>DOM Script Object Demo</h1> <button onclick="createScript()" class="btn">Create a script object</button> <script> function createScript() { var scriptElement = document.createElement("SCRIPT"); scriptElement.innerHTML="confirm('Are you able to create a script element?')"; document.body.appendChild(scriptElement); } </script> </body> </html>
Output
This will produce the following output −
Click on “Create a script object” button to create a script object −
Advertisements