User Tools

Site Tools


javascript

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.txt · Last modified: 2023/08/18 18:15 by 127.0.0.1