5

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
  }
})
android.nick
  • 11,069
  • 23
  • 77
  • 112
  • 1
    `not(':animated')` is not a check but is a selector. so it will return `[]` if all `'.wrapper'`s are animated – glebm Oct 25 '10 at 06:22

2 Answers2

6

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...");
}) 

Nico Westerdale
  • 2,147
  • 1
  • 24
  • 31
4

Here you have a working demo:

$('#button').click(function(){
if(    $('.wrapper:animated').length>0)
{
 $(".wrapper").text("animating")   ;
}
  if(
    $('.wrapper:animated').length<1) {
 $(".wrapper").text("not animating")   ;
  }
})
netadictos
  • 7,602
  • 2
  • 42
  • 69