Last active
December 22, 2015 11:39
-
-
Save ahsquared/6467488 to your computer and use it in GitHub Desktop.
select checkboxes to style: $(':checkbox').styleCheckboxes();
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
// select checkboxes to style: $(':checkbox').styleCheckboxes(); | |
$.fn.styleCheckboxes = function() { | |
$(this).each(function(index) { | |
if (!$(this).prev("a").hasClass('check-styled')) { | |
$(this).before("<a href='#check_" + index + "' class='check-styled' id='check_" + index + "'></a>").css({ | |
position: 'absolute', | |
left: -1, | |
top: 3, | |
zIndex: -1, | |
visibility: "hidden" | |
}); | |
if ($(this).prop('checked')) | |
$(this).prev().addClass('checked'); | |
$(this).change(function() { | |
if ($(this).prop('checked')) { | |
$(this).prev().addClass('checked'); | |
} else { | |
$(this).prev().removeClass('checked'); | |
} | |
}); | |
} | |
}); | |
// function to 'check' the styled ones and their matching checkboxes | |
$(".check-styled").on('click', function() { | |
$(this).next("input[type=checkbox]").trigger("click").trigger('change'); | |
return false; | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment