Am looking to have a button's icon class change only on the first click of the button event, which would also ajax .put a field to the db..
<div class="btn-group check-btns checkIt">
<button type="button" class="btn btn-xs dropdown-toggle" data-toggle="dropdown">
<span class="glyphicon glyphicon-unchecked"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="#">List Item 1</a></li>
</ul>
</div>
Tested this simple on.click first (http://jsfiddle.net/57268/1/), but thought that Bootstrap's built-in dropdown .open class toggle might prevent this..
$(document).ready(function () {
$(function () {
$('.checkIt').on('click', function () {
But changing it to listen to the dropdown being shown has yet to work either http://jsfiddle.net/57268/:
$(document).ready(function () {
$(function () {
$('.btn-group.check-btns.checkIt').on('show.bs.dropdown', function () {
console.log('checkIt clicked');
var $this = $(this);
var $that = $(this).children('.check-btns').children('.btn').find('.glyphicon')
if ($that.hasClass('.glyphicon-unchecked')) {
$that.removeClass('.glyphicon-unchecked').addClass('.glyphicon-check');
console.log('now checked icon');
$this.removeClass('.checkIt').addClass('.checkedIt');
console.log('now checkedIt class');
alert('checked and checkedIt .. now an ajax .put call');
}
})
});
});