Toggle navigation
Bootsnipp
Bootstrap
For
CSS Frameworks
Bootstrap
Foundation
Semantic UI
Materialize
Pure
Bulma
References
CSS Reference
Tools
Community
Page Builder
Form Builder
Button Builder
Icon Search
Dan's Tools
Diff / Merge
Color Picker
Keyword Tool
Web Fonts
.htaccess Generator
Favicon Generator
Site Speed Test
Snippets
Featured
Tags
By Bootstrap Version
4.1.1
4.0.0
3.3.0
3.2.0
3.1.0
3.0.3
3.0.1
3.0.0
2.3.2
Register
Login
"Bootstrap Button Select"
Bootstrap 3.3.0 Snippet by
peterxp
3.3.0
jQuery
Preview
HTML
CSS
JS
View Full Screen
Forked from
Fork
Fork this
Parent
1.2K
 
0 Fav
Post to Facebook
Tweet this
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <!------ Include the above in your HEAD tag ----------> <div class="container"> <h1>Bootstrap Button Select</h1> <div class="row"> <div class="col-xs-8 col-sm-4"> <a class="btn btn-default btn-select btn-select-light"> <input type="hidden" class="btn-select-input" id="" name="" value="" /> <span class="btn-select-value">Select an Item</span> <span class='btn-select-arrow glyphicon glyphicon-chevron-down'></span> <ul> <li id='1'>Option 1</li> <li id='2'>Option 2</li> <li id='3'>Option 3</li> <li id='4'>Option 4</li> </ul> </a> </div> </div> </div>
.btn-select { position: relative; padding: 0; min-width: 236px; width: 100%; border-radius: 0; margin-bottom: 20px; } .btn-select .btn-select-value { padding: 6px 12px; display: block; position: absolute; left: 0; right: 34px; text-align: left; text-overflow: ellipsis; overflow: hidden; border-top: none !important; border-bottom: none !important; border-left: none !important; } .btn-select .btn-select-arrow { float: right; line-height: 20px; padding: 6px 10px; top: 0; } .btn-select ul { display: none; background-color: white; color: black; clear: both; list-style: none; padding: 0; margin: 0; border-top: none !important; position: absolute; left: -1px; right: -1px; top: 33px; z-index: 999; } .btn-select ul li { padding: 3px 6px; text-align: left; } .btn-select ul li:hover { background-color: #f4f4f4; } .btn-select ul li.selected { color: white; } /* Default Start */ .btn-select.btn-default:hover, .btn-select.btn-default:active, .btn-select.btn-default.active { border-color: #ccc; } .btn-select.btn-default ul li.selected { background-color: #ccc; } .btn-select.btn-default ul, .btn-select.btn-default .btn-select-value { background-color: white; border: #ccc 1px solid; } .btn-select.btn-default:hover, .btn-select.btn-default.active { background-color: #e6e6e6; } /* Default End */ /* Primary Start */ .btn-select.btn-primary:hover, .btn-select.btn-primary:active, .btn-select.btn-primary.active { border-color: #286090; } .btn-select.btn-primary ul li.selected { background-color: #2e6da4; color: white; } .btn-select.btn-primary ul { border: #2e6da4 1px solid; } .btn-select.btn-primary .btn-select-value { background-color: #428bca; border: #2e6da4 1px solid; } .btn-select.btn-primary:hover, .btn-select.btn-primary.active { background-color: #286090; } /* Primary End */ .btn-select.btn-select-light .btn-select-value { background-color: white; color: black; }
$(document).ready(function () { $(".btn-select").each(function (e) { var value = $(this).find("ul li.selected").html(); if (value != undefined) { $(this).find(".btn-select-input").val(value); $(this).find(".btn-select-value").html(value); } }); }); $(document).on('click', '.btn-select', function (e) { e.preventDefault(); var ul = $(this).find("ul"); if ($(this).hasClass("active")) { if (ul.find("li").is(e.target)) { var target = $(e.target); target.addClass("selected").siblings().removeClass("selected"); var value = target.html(); $(this).find(".btn-select-input").val(value); $(this).find(".btn-select-value").html(value); } ul.hide(); $(this).removeClass("active"); } else { $('.btn-select').not(this).each(function () { $(this).removeClass("active").find("ul").hide(); }); ul.slideDown(300); $(this).addClass("active"); } }); $(document).on('click', function (e) { var target = $(e.target).closest(".btn-select"); if (!target.length) { $(".btn-select").removeClass("active").find("ul").hide(); } });
Questions / Comments:
Post
Posting Guidelines
Formatting
- Now
×
Close
Donate
BTC: 12JxYMYi6Vt3mx3hcmP3B2oyFiCSF3FhYT
ETH: 0xCD715b2E3549c54A40e6ecAaFeB82138148a6c76