Last active
December 26, 2015 08:09
-
-
Save st3phan/7120803 to your computer and use it in GitHub Desktop.
Nested checkboxes. Do not return parents checkboxes when it has child checkboxes checked.
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script> | |
<meta charset=utf-8 /> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<ul id="thingy"> | |
<li><span><input type="checkbox" checked /></span> | |
<ul> | |
<li><span><input type="checkbox" /></span></li> | |
<li><span><input type="checkbox" checked /></span></li> | |
<li><span><input type="checkbox" /></span></li> | |
</ul> | |
</li> | |
<li><span><input type="checkbox" /></span></li> | |
<li><span><input type="checkbox" checked /></span> | |
<ul> | |
<li><span><input type="checkbox" /></span></li> | |
<li><span><input type="checkbox" checked /></span> | |
<ul> | |
<li><span><input type="checkbox" /></span></li> | |
<li><span><input type="checkbox" checked /></span></li> | |
<li><span><input type="checkbox" checked /></span></li> | |
</ul> | |
</li> | |
<li><span><input type="checkbox" /></span></li> | |
<li><span><input type="checkbox" /></span></li> | |
</ul> | |
</li> | |
<li><span><input type="checkbox" checked /></span></li> | |
</ul> | |
</body> | |
</html> |
This file contains 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
$('input:checked').filter(function() { | |
if (!$(this).closest('li').find('> ul input').length) { | |
return $(this); | |
} | |
}).parent().css({ background: 'red' }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment