
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
HTML DOM scripts Collection
The HTML DOM Script collection returns the collection of all <script> elements of an HTML document.
Syntax
Following is the syntax −
document.scripts
Property of script object
Property | Explanation |
---|---|
length | It returns the number of <script> element in the collection in a HTML document. |
Methods of script object
Method | Explanation |
---|---|
[index] | It returns the specified index <script> element from the collection. |
item(index) | It returns the specified index <script> element from the collection. |
namedItem(id) | It returns the specified id <script> element from the collection. |
Example
Let us see an example of scripts collection −
<!DOCTYPE html> <html> <head> <style> html{ height:100%; } body{ text-align:center; color:#fff; background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) center/cover no-repeat; height:100%; } p{ font-weight:700; font-size:1.2rem; } ul{ list-style-type: none; padding:0; } .btn{ background:#0197F6; border:none; height:2rem; border-radius:2px; width:50%; margin:2rem auto; display:block; color:#fff; outline:none; cursor:pointer; } .show{ font-size:1.5rem; font-weight:bold; } </style> </head> <body> <script> console.log("script one"); </script> <h1>DOM scripts Collection Demo</h1> <p>Hi, There are two script elements on this page:</p> <script> console.log("script two"); </script> <button onclick="show()" class="btn">Show No. Of Script</button> <div class='show'></div> <script> function show() { var scriptList = document.scripts; document.querySelector(".show").innerHTML=scriptList.length; } </script> </body> </html>
Output
This will produce the following output −
Click on “Show No. of Script” button to display the number of scripts elements.
- Related Articles
- HTML DOM links Collection
- HTML DOM Anchor Collection
- HTML DOM embeds collection
- HTML DOM forms collection
- HTML DOM Datalist options Collection
- HTML DOM Table rows Collection
- HTML DOM Table tBodies Collection
- HTML DOM Images Collection Property
- HTML DOM HTML Object
- HTML DOM AnimationEvent
- HTML DOM DragEvent
- HTML DOM HashChangeEvent
- HTML DOM tagName Property
- HTML DOM Ins Object
- HTML DOM HR Object

Advertisements