I am trying to removeClass from "li" but it doesn't work. Here is my function:
function setStore($s, id, name) {
//alert("length: " + $s.parents('ul.popup-cbo-menu').find('li.selected').length);
$s.parents('ul.popup-cbo-menu').find('li.selected').removeClass('selected');
//alert("length: " + $s.parents('ul.popup-cbo-menu').find('li.selected').length);
//$s.parent('li').addClass('selected');
$('#cboStores').val(name);
}
I can confirm that the "selected" is removed by putting alert. But for some reason, it doesn't affect the actual "li".
Here is the jsfiddle: http://jsfiddle.net/87xswem7/9/. However, but for some reason, jsFiddle is unable to find setStore() function.
Here is how I create the popover:
$(document).ready(function () {
$("#cboStores").popover({
viewport: 'body',
trigger: 'click',
placement: 'bottom',
html: true,
content: '<ul class="popup-cbo-menu">' +
' <li><a href="#" onclick="setStore($(this), -1, \'All Stores\')">All Stores</a></li>' +
' <li class="selected"><a href="#" onclick="setStore($(this), 1, \'My Foot\')">My Foot</a></li>' +
' <li><a href="#" onclick="setStore($(this), 2, \'My Foot 1\')">My Foot 1</a></li>' +
'</ul>',
template: '<div class="popover cont-popup-cbo-menu" role="tooltip">' +
' <div class="arrow"></div><h3 class="popover-title"></h3>' +
' <div class="popover-content"></div>' +
'</div>'
}).blur(function () {
$(this).popover('hide');
});
});
And here is my input box in html:
<input type="text" id="cboStores" value="My Foot" />