Skip to content

Instantly share code, notes, and snippets.

@atatos
Last active December 21, 2015 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atatos/6341832 to your computer and use it in GitHub Desktop.
Save atatos/6341832 to your computer and use it in GitHub Desktop.
This code can be used for skinned input type radiobutton
.radiobox {
background: url("../img/common/radiobox.png") no-repeat scroll 0 0 transparent;
cursor: pointer;
display: inline-block;
float: left;
height: 11px;
margin: 0 5px 0 0;
position: relative;
width: 11px;
}
.radiobox.on {
background-position: 0 -13px;
}
.radiobox input {
cursor: pointer;
height: 11px;
left: 0;
margin: 0;
opacity: 0;
padding: 0;
position: absolute;
top: 0;
width: 11px;
}
<div class="categoryRadio">
<span class="radiobox">
<input type="radio" checked="checked" id="radio_1" value="radio one" name="radio[]">
</span>
</div>
radioBox : function() {
var radioBox = $('.radiobox');
// if an input is selected in page loading
radioBox.find('input[type="radio"]').each(function(index, key) {
if ( $(this).is(':checked') ) {
$(this).parent().addClass('on');
}
});
radioBox.find('input[type="radio"]').on('change', function() {
var parent = $(this).parents('.categoryRadio');
parent.find('.radiobox').removeClass('on');
if ( $(this).is(':checked')) {
$(this).parent().addClass('on');
}else {
$(this).parent().removeClass('on');
}
});
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment