Skip to content

Instantly share code, notes, and snippets.

@jordanneenan
Created February 22, 2017 02:31
Show Gist options
  • Save jordanneenan/5a59820314a8ebcf137866795bab9de5 to your computer and use it in GitHub Desktop.
Save jordanneenan/5a59820314a8ebcf137866795bab9de5 to your computer and use it in GitHub Desktop.
Custom checkbox with javascript
$(document).ready(function(){
//hide the checkboxes
$('.ginput_container_checkbox li input').hide();
//inject the custom checkbox code
$('.ginput_container_checkbox li input').before('<div class="custom_checkbox"><div class="check_inner"></div></div>');
//control the new checkbox on click
$('.ginput_container_checkbox li').on('click', '.custom_checkbox', function(){
checkBox($(this));
});
//disable the lable from activation the hidden checkbox
$('.ginput_container_checkbox li label').click(function(event){
event.preventDefault();
});
});
function checkBox($elem){
if($elem.hasClass('active')){
$elem.removeClass('active');
$elem.next().prop('checked', false);
}else{
$elem.addClass('active');
$elem.next().prop('checked', true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment