Skip to content

Instantly share code, notes, and snippets.

@lorepirri
Created April 20, 2017 17:39
Show Gist options
  • Save lorepirri/aeafc27f289416c9cbba650d66e7d515 to your computer and use it in GitHub Desktop.
Save lorepirri/aeafc27f289416c9cbba650d66e7d515 to your computer and use it in GitHub Desktop.
Simple snippet of a dropdown menu which acts as a radio button: its label gets updated with the selected value
<!-- show all/online/offline dropdown -->
<div class="btn-group btn-right">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Show All <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a href="#">Show All</a></li>
<li><a href="#">Online</a></li>
<li><a href="#">Offline</a></li>
</ul>
</div>
<!-- END: show all/online/offline dropdown -->
$(document).ready(function() {
// ...
// on filter channel status change
$('.dropdown-menu li a').click(function (e) {
var newHeading = $(this).text();
var $heading = $('.dropdown-toggle');
var $caret = $('.caret', $heading);
$heading.html(newHeading + ' ').append($caret);
filterChannelsByStatus(newHeading);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment