Created
February 22, 2017 02:31
-
-
Save jordanneenan/5a59820314a8ebcf137866795bab9de5 to your computer and use it in GitHub Desktop.
Custom checkbox with javascript
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
$(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