The getElementById() method returns the first element with the specified id.
document.getElementById(id)
Parameter | Description |
---|---|
id | The id of the element to retrieve. |
var el = document.getElementById("theId"); alert(el.textContent); // the content of the element
The getElementsByName() method returns an array of all elements with the specified name.
document.getElementsByName(name)
Parameter | Description |
---|---|
name | The name of the elements to get. |
var arr = document.getElementsByName("name"); alert(arr.length); // the number of elements returned