Skip to content

Instantly share code, notes, and snippets.

@getsetbro
Created November 21, 2013 23:14
Show Gist options
  • Save getsetbro/7591601 to your computer and use it in GitHub Desktop.
Save getsetbro/7591601 to your computer and use it in GitHub Desktop.
.btn{
display:inline-block;
color:#333;
border:1px solid #999;
background-color:#ccc;
cursor:pointer;
padding:8px 12px;
font-size:14px;
background-image: linear-gradient(#ddd, #aaa);
}
.btn:hover{
background-color:#eee;
}
.btn-group{
display:inline-block;
}
.btn-group .btn{
margin:0 -5px 0 0
}
.btn-group .btn:first-child{
border-radius:3px 0 0 3px
}
.btn-group .btn:last-child{
border-radius:0 3px 3px 0;
margin:0
}
.btn.active{
outline:none;
position:relative;
background-image: linear-gradient(#bbb, #eee);
}
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="radio buttons prototype function" />
<meta charset=utf-8 />
<title>bs radio</title>
<script src="http://code.jquery.com/jquery.min.js"></script>
</head>
<body>
<p>
<div class="btn-group" data-toggle="buttons-radio">
<button class="btn">Left</button>
<button class="btn active">Middle</button>
<button class="btn">Right</button>
</div>
</p>
<p>
<div class="btn-group" data-toggle="buttons-radio">
<button class="btn">Left</button>
<button class="btn">Middle</button>
<button class="btn">Right</button>
</div>
</p>
<p>
<div class="btn-group" data-toggle="buttons-radio">
<button class="btn">Left</button>
<button class="btn">Middle</button>
<button class="btn">Right</button>
</div>
</p>
</body>
</html>
var RadioBtn = (function(){
var RadioBtn = function(groupElement){
this.groupElement = $(groupElement);
self = this;
$('.btn', this.groupElement).click(function(){
self.toggle(this);
});
};
RadioBtn.prototype.toggle = function(toBeToggled){
$(toBeToggled).addClass('active').siblings('.active').removeClass('active');
};
RadioBtn.MakeRadioBtn = function(elements){
elements.each(function(index, groupElement){
new RadioBtn(groupElement);
});
};
return RadioBtn;
})();
RadioBtn.MakeRadioBtn($('.btn-group'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment