Skip to content

Instantly share code, notes, and snippets.

@MohHeader
Last active September 2, 2015 06:08
Show Gist options
  • Save MohHeader/9049262 to your computer and use it in GitHub Desktop.
Save MohHeader/9049262 to your computer and use it in GitHub Desktop.
Use ul,li to create a Radio-Button-like input
<ul id="ul" data-name="name">
<li data-value="1">1</li>
<li data-value="2">2</li>
<li data-value="3">3</li>
</ul>
<script type="text/javascript">
$.extend($.fn, {
radioNizer: function () {
this.each(function () {
this.$inputNizer = $('<input name="'+$(this).data('name')+'" type="hidden" />')
$(this).append(this.$inputNizer)
$(this).children().on('click',function(){
$($(this).parent().children('input')).attr('value',$(this).data('value'))
})
});
}
})
$('#ul').radioNizer();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment