Created
June 5, 2012 13:34
-
-
Save kujon/2875028 to your computer and use it in GitHub Desktop.
JavaScript: Radio button and checkbox replacement
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
/** | |
* Radio button and checkbox replacement | |
* Author: Jakub Korzeniowski | |
* Agency: Softhis | |
* http://www.softhis.com | |
*/ | |
(function($) { | |
$.fn.checked = function() { | |
return this.each(function() { | |
var $org = $(this).filter(':radio, :checkbox'), | |
$repl = $('<span />', { | |
class: $org.attr('type') | |
}); | |
if($org.is(':checked')) { | |
$repl.addClass('checked'); | |
} | |
$org.css({ | |
visibility: 'hidden', | |
position: 'absolute', | |
'z-index': -1 | |
}).after($repl.bind('click', function(e) { | |
if($repl.hasClass('checked')) { | |
$repl.removeClass('checked'); | |
$org.attr('checked', false); | |
} else { | |
$repl.addClass('checked'); | |
$org.attr('checked', true); | |
} | |
})); | |
}); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment