I am essentially adding radio-buttons functionality to buttons with the class “tagbutton”. There is a flaw with my code, because _this is never _last…
taguid = "";
_last = "";
$('.tagbutton').live('click', function() {
_this = $(this);
if(_last) {
//There was a last object
if(_last == _this) { // The last object was the current object
alert('deactiveate for this obj');
} else { // The last object was not the current object
alert('deactivate last, activate this');
}
} else {
alert('first object activated');
var taguid = $(this).prev().attr('data-uid');
alert(taguid);
_last = $(this);
}
});
It’s because the objects’ references aren’t the same. A simpler way might be to activate the clicked one, then deactivate the last one. It’ll have the same effect: