Set the Dropdown Button to the Selected Menu Item


$('#container').on('click', '.dropdown-menu a', function () {
      var parentElem = $(this).parent().parent();
      var $dropdown = $(parentElem);
      $dropdown.find('button').text($(this).text()).append(' <span class="caret"></span>');
});