jquery: this.not (':animated') && that.is (':visible') not following the rules, syntax problem? only few lines of code

android.nick picture android.nick · Oct 25, 2010 · Viewed 13.1k times · Source

when i click on #button, it's stilling doing the 'do something', even though .wrapper is animating and .wrapper span is not visible. so it's not following the rules. what's wrong?

$('#button').click(function(){
  if(
    $('.wrapper').not(':animated') && $('.wrapper span').is(':visible')
  ) {
    //do something
  }
})

Answer

Nico Westerdale picture Nico Westerdale · Jun 22, 2012

This is a bit cleaner without the if statements. working demo

$('#button').click(function(){ 
    $('.wrapper').filter(':animated').text("animating...");
    $('.wrapper').filter(':not(:animated)').text("not animating...");
})