javascript - How to calculate interval time when same button clicked twice in java script or jquery -



javascript - How to calculate interval time when same button clicked twice in java script or jquery -

there 1 button java script of j query , first time press button, after seconds 1 time again press same button. how calculate interval time between 2 presses of same button. please can help.

code tried: code downwards , ip, how can calculate same button preesing

var starttime, endtime; $("#bu").on('mousedown', function () { starttime = new date().gettime(); }); $("#bu").on('mouseup', function () { endtime = new date().gettime(); longpress = (endtime - starttime < 500) ? false : true; });

try this

class="snippet-code-js lang-js prettyprint-override">var starttime; $("#bu").on('click', function() { if(starttime) { alert( "time difference: " + (new date().gettime() - starttime) ); starttime = undefined; } else { starttime = new date().gettime(); } }); class="snippet-code-html lang-html prettyprint-override"><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <input type="button" id="bu" value="click me" />

javascript jquery dom javascript-events

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -