HTML DOM Document getElementsByName() ກົນລະບຽບ
- Previous Page getElementsByClassName()
- Next Page getElementsByTagName()
- Back to Top ບັນດາວ່າງໂດມດາມເດໂມແກຣັສ
ການກໍານົດ ແລະ ການນໍາໃຊ້
getElementsByName()
ກົນລະບຽບກັບກຸ່ມພັງທີ່ມີຊື່ຫາງຄົງຄຽງ.
getElementsByName()
ກົນລະບຽບກັບສານ. NodeList.
NodeList
NodeList ເປັນກຸ່ມພັງທີ່ຄ້າຍຄືກັບອາວຸດ (ລາຍການ).
ສາມາດເຂົ້າເຖິງພັງທີ່ຢູ່ໃນລາຍການໂດຍການໃຊ້ບັນທາ. ບັນທາເລີ່ມຈາກ 0.
length ການກັບຄືນຈຳນວນຂອງພັງທີ່ຢູ່ໃນລາຍການກັບຄືນ.
ບໍ່ມີການເວົ້າໃສ່
Example
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 by the order of elements in the document. |
Browser support
document.getElementsByName()
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()
- Back to Top ບັນດາວ່າງໂດມດາມເດໂມແກຣັສ