I'm trying learn if else statements with jQuery and hasClass. I've done a simple test that won't work and I can't figure out why.
if ($('.one').hasClass('left')) {
$('.button').click(function () {
$('.one').addClass('right');
$('.one').removeClass('left');
})
} else {
$('.button').click(function () {
$('.one').addClass('left');
$('.one').removeClass('right');
})
}
I'm very confused because when I go to the dev tools in Chrome, the first click of the button works fine, and the classes are switched correctly and left is removed. I'm not sure why the else statement won't work though. Everything looks correct to me.
iflogic inside of a single event handler, and poof, there goes your problem!