<p id="birinci"> ilk paragraf</p>
<p name="yazar">ikinci pragraf</p>
<p name="yazar">üçüncü paragraf</p>
<p>dördüncü paragraf</p>
<script>
var nesneler= document.getElementsByName("yazar");
console.log(nesneler);
//Console.log ekranını açmak için CTRL+SHIFT+I tuşarını kullanınız.
</script>
<!DOCTYPE html>
<html>
<body>
<p>How to check a checkbox using getElementByName() method in JavaScript</p>
Tiger: <input name="forestAnimal" type="checkbox" value="Tiger">
Cow: <input name="domesticAnimal" type="checkbox" value="Cow">
<button onclick="retriveElementByName()" id="btnClick">Click</button>
<script>
function retriveElementByName(){
var animalName = document.getElementsByName("domesticAnimal");
var i;
for (i = 0; i < animalName.length; i++) {
if (animalName[i].type == "checkbox") {
animalName[i].checked = true;
}
}
}
</script>
</body>
</html>
/*
The document.getElementsByName() method returns all the element
of specified name.
*/
// Syntax : document.getElementsByName("name")
<script type="text/javascript">
function totalelements()
{
var allgenders=document.getElementsByName("gender");
alert("Total Genders:"+allgenders.length);
}
</script>
<form>
Male:<input type="radio" name="gender" value="male">
Female:<input type="radio" name="gender" value="female">
<input type="button" onclick="totalelements()" value="Total Genders">
</form>