Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Solution: use <code>setInterval</code> and <code>clearInterval</code> instead of timeout, because setTimeout only executes the closure function once, or <code>setTimeout</code> in your closure function.</p> <p>Example for using <code>setTimeout</code> in the function itself:</p> <pre><code>$('.bid-up').live('mousedown',function() { var button = $(this); function asd(){ var number = button.parent('div').siblings('#bid-child-container-2').find('#bid-price').val(); var newnumber = number.split('.'); var on = button.attr('data-on'); button.siblings('#bid-down').attr('data-on','1'); if(newnumber[1]&lt;9) { var first = newnumber[0]; var second = parseInt(newnumber[1])+1; } if(newnumber[1]==9) { var first = parseInt(newnumber[0])+1; var second = 0; } var finalnumber = first+'.'+second; button.parent('div').siblings('#bid-child-container-2').find('#bid-price').val(finalnumber); timeoutId = setTimeout(asd, 20); } timeoutId = setTimeout(asd, 20); }).bind('mouseup mouseleave', function() { clearTimeout(timeoutId); }); </code></pre> <p>example using <code>setInterval</code> and <a href="http://api.jquery.com/data/" rel="nofollow"><code>data</code></a> to store interval id.</p> <pre><code>$('.bid-up').live('mousedown',function() { var button = $(this); button.data('interval', setInterval(function (){ var number = button.parent('div').siblings('#bid-child-container-2').find('#bid-price').val(); var newnumber = number.split('.'); var on = button.attr('data-on'); button.siblings('#bid-down').attr('data-on','1'); if(newnumber[1]&lt;9) { var first = newnumber[0]; var second = parseInt(newnumber[1])+1; } if(newnumber[1]==9) { var first = parseInt(newnumber[0])+1; var second = 0; } var finalnumber = first+'.'+second; button.parent('div').siblings('#bid-child-container-2').find('#bid-price').val(finalnumber); }, 20)); }).bind('mouseup mouseleave', function() { clearInterval(button.data('interval')); }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload