javascript
This is an old revision of the document!
Table of Contents
Get Element
getElementById()
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
getElementsByName()
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
javascript.1366763761.txt.gz · Last modified: 2023/08/18 18:15 (external edit)