var getCheckBox = document.getElementsByClassName('checkbox');
var i = 0;
function selectAll(SelectAllCheckBox){
if (SelectAllCheckBox.checked) {
while (i < getCheckBox.length){
getCheckBox[i].checked = true;
i++
}
}
else{
while(i < getCheckBox.length){
getCheckBox[i].checked = false;
i++
}
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Select All Checks</title>
</head>
<body>
<label><input type="checkbox" onchange="selectAll(this)">Select All</label><br><br>
<div>
<label><input type="checkbox" class="checkbox">checkbox 1</label><br>
<label><input type="checkbox" class="checkbox">checkbox 2</label><br>
<label><input type="checkbox" class="checkbox">checkbox 3</label><br>
<label><input type="checkbox" class="checkbox">checkbox 4</label><br>
<label><input type="checkbox" class="checkbox">checkbox 5</label><br>
<label><input type="checkbox" class="checkbox">checkbox 6</label><br>
</div>
</body>
</html>
Hello Guys, I found above code to select all checkboxes and for selecting all checkboxes the code is working, but when I'm deselecting all checkboxes code stopped working and it's not showing any error in console either.
Please help me
Aucun commentaire:
Enregistrer un commentaire