Javascript DOM HTML HTMLCollection

Introduction

An HTMLCollection object is an array-like list of HTML elements.

Methods like the getElementsByTagName() returns an HTMLCollection.

The following properties and methods can be used on a HTMLCollection object:

Property / Method Description
item()Returns the element at the specified index in an HTMLCollection
lengthReturns the number of elements in an HTMLCollection
namedItem() Returns the element with the specified ID, or name, in an HTMLCollection

Get an HTMLCollection:

var x = document.getElementsByTagName("P"); 
// Returns a collection of all the P elements in the document

View in separate window

<!DOCTYPE html>
<html>
<body>
<p>Use the getElementsByTagName() method to return an HTMLCollection:</p>

<script>
var x = document.getElementsByTagName("P");
document.write(x);//  ww w .  j a v  a  2  s  .c om
</script>

</body>
</html>



PreviousNext

Related