English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
scriptsThe attribute returns<script>List of elements.
The elements in the list are sorted in the order they appear in the source code.
document.scripts
var x = document.scripts.length;Test and see‹/›
All browsers fully support the scripts attribute:
Attribute | |||||
scripts | Is | Is | Is | Is | Is |
Attribute | Description |
---|---|
length | Return the list in<script>Number of elements |
Method | Description |
---|---|
[index] | Return the specific node at the given zero-based index in the list. If the index number is out of range, return null. |
item(index) | Return the specific node at the given zero-based index in the list. If the index number is out of range, return null. |
namedItem(id) | Returns the specific node whose ID name matches the string specified by name. If the id does not exist, it returns null. |
Return Value: | oneHTMLCollection. You can use it like an array to get all elements in the list |
---|---|
DOM Version: | DOM Level3 |
Display the content of the first script element in the document (index 0):
var x = document.scripts[0].text;Test and see‹/›
Traverse all script elements and display the text content of each script:
var my_list = document.scripts; for (let i = 0; i < my_list.length;++) { document.getElementById("x").innerHTML += my_list[i].text + "<br>"; }Test and see‹/›