Created
May 4, 2016 20:30
-
-
Save maximishchenko/c0225452318360f373db97518e320d56 to your computer and use it in GitHub Desktop.
Check/Uncheck all checkboxes in div
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="test"> | |
<input type="checkbox"> | |
<input type="checkbox"> | |
<input type="checkbox"> | |
<input type="checkbox"> | |
<input type="checkbox"> | |
</div> | |
<script type="text/javascript"> | |
function checkByParent(aId, aChecked) { | |
var collection = document.getElementById(aId).getElementsByTagName('INPUT'); | |
for (var x=0; x<collection.length; x++) { | |
if (collection[x].type.toUpperCase()=='CHECKBOX') | |
collection[x].checked = aChecked; | |
} | |
} | |
checkByParent('test', true); | |
</script> | |
#Buttons | |
<input type="button" value="Check All" onclick="checkByParent('test', true);"> | |
<input type="button" value="Uncheck All" onclick="checkByParent('test', false);"> | |
#Links | |
<a href="#" onclick="checkByParent('test', true); return false;">Check all</a> | |
<a href="#" onclick="checkByParent('test', false); return false;">Uncheck all</a> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment