HTML DOM Document getElementsByName() Method
- Previous page getElementsByClassName()
- Next page getElementsByTagName()
- Sarwarin HTML DOM Documents
Definition and Usage
getElementsByName()
Hanyar samun cece ce kwarin sunan kanan.
getElementsByName()
Hanyar samun cece ce kaiyaki. NodeList.
NodeList
NodeList Ita ce ɗaukaka na ɗan tattara kamar kwallon doki (list).
Za a iya samun ɗaukaka na ɗan tattara ta hanyar index. Index baya 0.
length Yanqu kwarin cece na ɗaukaka na ɗan tattara.
Kaiko ciyaya:
Instance
Example 1
Get all elements with name="fname":
let elements = document.getElementsByName("fname");
Example 2
Return the number of elements with name="animal":
let num = document.getElementsByName("animal").length;
Example 3
Check all <input> elements with type="checkbox" and name="animal":
const collection = document.getElementsByName("animal"); for (let i = 0; i < collection.length; i++) { if (collection[i].type == "checkbox") { collection[i].checked = true; } }
Syntax
document.getElementsByName(name)
Parameter
Parameter | Description |
---|---|
name | Required. The value of the element's name attribute. |
Return value
Type | Description |
---|---|
Object |
NodeList object. Collection of elements with specified name. Sorted according to the order of elements in the document. |
Browser support
document.getElementsByName()
It is DOM Level 1 (1998) feature.
All browsers support it:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Support | 9-11 | Support | Support | Support | Support |
- Previous page getElementsByClassName()
- Next page getElementsByTagName()
- Sarwarin HTML DOM Documents