"Toggle On - Off"
Bootstrap 3.3.0 Snippet by lookbadgers

<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"> <div class="row"> <h2>Create your snippet's HTML, CSS and Javascript in the editor tabs</h2> <div> <div class="btn-group btn-toggle" data-toggle="buttons"> <label class="btn btn-default"> <input type="radio" name="field" value="YES"> Yes oh yes! </label> <label class="btn btn-primary active"> <input type="radio" checked="checked" name="field" value="NO"> Oh No! </label> </div> </div> </div> </div>
(function ($) { console.log('aa'); console.log($('.btn-toggle')); $('.btn-toggle').on('click',function(e) { var $target = $(e.target); if ($target.hasClass('active')) { return; } $(this).find('.btn').toggleClass('active'); if ($(this).find('.btn-primary').length>0) { $(this).find('.btn').toggleClass('btn-primary'); } if ($(this).find('.btn-danger').length>0) { $(this).find('.btn').toggleClass('btn-danger'); } if ($(this).find('.btn-success').length>0) { $(this).find('.btn').toggleClass('btn-success'); } if ($(this).find('.btn-info').length>0) { $(this).find('.btn').toggleClass('btn-info'); } $(this).find('.btn').toggleClass('btn-default'); //reset $('.btn-toggle > .btn:last-child').click(); }); })(jQuery);

Related: See More


Questions / Comments: