javascript - jQuery timout function interfering with toggling -


i have checkbox want stay checked 7 seconds , uncheck itself. i've put below code, despite trying clear timeout, seems interfere toggling if user clicks several times on toggle.

can me find cleaner way won't mis-behave if users click frequently?

$('input#foo').on('change', function(){     cleartimeout(timeout);     if ( $(this).is(':checked') ) {         $('#box').addclass('splash').stop();         $( "div.title" ).html( 'hide thing' );         var timeout = settimeout(function() {           if ( $('input#foo').is(':checked') ) {             $('input#foo').prop('checked', false).change();           }         }, 7000);     }      else {         $('#box').removeclass('splash').stop();         $( "div.title" ).html( 'reveal thing' );      }   }); 

remove .change() line,and try it. $('input#foo').prop('checked', false);


Comments

Popular posts from this blog

'hasOwnProperty' in javascript -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -

How to understand 2 main() functions after using uftrace to profile the C++ program? -