I have some problem. I need to add some class for specify element for a bit time. When this class is on live i want to execute one condition, but if is not execute another. Something is not right, can u help me? This is my code:
btn.live('click', function(e){
info_board.addClass('animation_time');
setTimeout(function(){
info_board.removeClass('animation_time')
}, 700);
if (info_board.not('animation_time')){
info_board.addClass('flying_info_board_out').removeClass('flying_info_board');
}
else if (info_board.hasClass('animation_time')){
setTimeout(function(){
info_board.addClass('flying_info_board_out').removeClass('flying_info_board');
}, 500);
}
});
When using
.not(), you still need to use.selector to target a class. So use:.lengthis needed because.not()returns a set of matched elements, which is a jQuery object with 0 or more items. But jQuery objects are always truthy in anifstatement. So you need the right thing to check, which would be to check for how many matched elements were returned from.not()with the.lengthproperty.At the same time, there’s no reason to have
else if…just useelse.Since
.hasClass()is probably less processing for jQuery than.not(), you might as well use: