Created
June 9, 2013 13:10
-
-
Save UmeshSingla/5743464 to your computer and use it in GitHub Desktop.
Select all Checkboxes, Unselect all Checkboxes
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
jQuery('body').on('click','.topic-checkbox input[type="checkbox"]', function(){ | |
var current_checkbox = jQuery(this); | |
var id = current_checkbox.attr('id'); | |
var checked = current_checkbox.prop('checked'); | |
if(id=="checkbox-input-all" && checked){ | |
jQuery('.topic-checkbox input[type="checkbox"]').prop('checked', true); | |
}else if(id=="checkbox-input-all" && !checked){ | |
jQuery('.topic-checkbox input[type="checkbox"]').prop('checked', false); | |
}else if(id!="checkbox-input-all" && !checked){ | |
jQuery('#checkbox-input-all').prop('checked', false); | |
}else if( jQuery('.checkbox:checked').length == jQuery('.checkbox').length) { | |
jQuery('.topic-checkbox input[type="checkbox"]').prop('checked', true); | |
} | |
}); |
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
<ul class="topic-list"> | |
<li class="topic-checkbox" id="all_topics"> | |
<span><input type="checkbox" name="slected_topics[]" id="checkbox-input-all" value="all"/></span> | |
<span class="checkbox-label"><label for="checkbox-input-all">Select All</label></span> | |
</li> | |
<li class="topic-checkbox"> | |
<span><input type="checkbox" name="slected_topics[]" class="checkbox" id="checkbox-input-0" value="4"/></span> | |
<span class="checkbox-label"><label for="checkbox-input0">Animals</label></span> | |
</li> | |
<li class="topic-checkbox"> | |
<span><input type="checkbox" name="slected_topics[]" class="checkbox" id="checkbox-input-1" value="5"/></span> | |
<span class="checkbox-label"><label for="checkbox-input1">Art</label></span> | |
</li> | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment