Last active
December 21, 2015 17:39
-
-
Save atatos/6341832 to your computer and use it in GitHub Desktop.
This code can be used for skinned input type radiobutton
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
.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; | |
} |
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
<div class="categoryRadio"> | |
<span class="radiobox"> | |
<input type="radio" checked="checked" id="radio_1" value="radio one" name="radio[]"> | |
</span> | |
</div> |
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
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