Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
  }
})
like image 387
android.nick Avatar asked Oct 25 '10 06:10

android.nick


2 Answers

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

like image 67
Nico Westerdale Avatar answered Oct 06 '22 12:10

Nico Westerdale


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")   ;
  }
})
like image 25
netadictos Avatar answered Oct 06 '22 11:10

netadictos