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

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -