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
Post a Comment