images collection
Represents a collection of all img elements in the current document.
Note: the images collection does not contain the input:image elements, only the img elements.
The elements in the collection are sorted in source code order.
Syntax:
Properties that reference the object:
| document.images |
The base interface, through which you can add new functionalities to the images 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 images collection:
|
||||
<head> <script type="text/javascript"> function GetImages () { var len = document.images.length; alert ("There are " + len + " images in the document."); } </script> </head> <body> <img src="bg.jpg" /> <img src="rainbow.gif"/> <br /><br /> <button onclick="GetImages ();">Get the number of images!</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 2:
This example shows that the images collection does not contain the input:image elements:
|
||||
<head> <script type="text/javascript"> function GetImages () { var len = document.images.length; if (len == 0) { alert ("There is no image in the document."); } else { alert ("There are " + len + " images in the document."); } } </script> </head> <body> <input type="image" src="bg.jpg" /> <input type="image" src="rainbow.gif"/> <br /><br /> <button onclick="GetImages ();">Get the number of images!</button> </body> |
||||
|
||||
Did you find this example helpful?
|
External links:
User Contributed Comments