getElementsByName() method
getElementsByName() Method
Definition and usage
getElementsByName() method can return the name with the specified name A collection of objects.
Syntax
document.getElementsByName(name)
Description | |
---|---|
name | Required. The name of the element.
Browser support
##All major browsers support the getElementsByName() method
InstanceInstance
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script>
function getElements(){
var x=document.getElementsByName("x");
alert(x.length);
}
</script>
</head>
<body>
猫:
<input name="x" type="radio" value="猫">
狗:
<input name="x" type="radio" value="狗">
<input type="button" onclick="getElements()" value="多少名称为 'x'的元素?">
</body>
</html>
Run Instance»Click the "Run Instance" button View online examples