scripts collection
Represents a collection of all script elements in the current document.
The elements in the collection are sorted in source code order.
Syntax:
Properties that reference the object:
| document.scripts |
The base interface, through which you can add new functionalities to the scripts collection, is the HTMLCollection interface.
Possible members:
Properties:
Returns an integer that specifies the number of elements in the current collection.
This property is read-only. |
Methods:
[nameOrIndex] |
Returns an element or a collection of elements from the current collection by name or index.
Parameters:
Return value:
|
||||||||||||||||||||||
item (nameOrIndex [, subIndex]) |
Returns an element or a collection of elements from the current collection by name or index.
Parameters:
Return value:
|
||||||||||||||||||||||
namedItem (name) |
Returns an element or a collection of elements from the current collection by name.
Parameters:
Return value:
|
||||||||||||||||||||||
tags | Returns a NodeList collection that contains all elements from the current collection with the specified tag name. | ||||||||||||||||||||||
urns | Returns a NodeList collection that contains all elements to which the specified behavior is attached. |
Example HTML code 1:
This example illustrates the use of the scripts collection:
|
||||
<head> <script type="text/javascript"> function GetFirstScript () { if ('scripts' in document) {// Internet Explorer, Opera, Google Chrome and Safari var scripts = document.scripts; } else { var scripts = document.getElementsByTagName ("script"); } alert (scripts[0].text); } </script> </head> <body> <button onclick="GetFirstScript ();">Get the contents of the first script tag!</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 2:
Recommandation (because all commonly used browsers supports the getElementsByTagName method):
|
||||
<head> <script type="text/javascript" id="myScript"> function GetFirstScript () { var scripts = document.getElementsByTagName ("script"); alert (scripts[0].text); } </script> </head> <body> <button onclick="GetFirstScript ();">Get the contents of the first script tag!</button> </body> |
||||
|
||||
Did you find this example helpful?
|
External links:
User Contributed Comments