Calculating the time between two clicks in Javascript

javascript calculate time difference between two timestamps
calculate the time difference between two times in minutes in javascript
javascript timestamp
get minutes between two datetime javascript
javascript how many minutes between two dates
time between clicks

I want to calculate the time between two clicks of an attribute with javascript but I don't know how.

For example;

<a href="#">click here</a>

if the user clicks more than once -let's say in 5 seconds- I want to display an alert. I'm using jQuery if that helps. I don't know much about javascript but I've been coding a small project in my free time.

Something like this would do the trick. Keep a variable with the time of the last click and then compare it when the user clicks the link again. If the difference is < 5 seconds show the alert

<a id='testLink' href="#">click here</a>
<script type='text/javascript'>
    var lastClick = 0;
    $("#testLink").click(function() {
        var d = new Date();
        var t = d.getTime();
        if(t - lastClick < 5000) {
             alert("LESS THAN 5 SECONDS!!!");
        lastClick = t;

jquery - Calculating the time between two clicks in Javascript, jQuery: Time between the two click events on a paragraph <html> <head> < script src="//"></script>  startTimer() should set a start_time variable (or something similarly named), and stopTimer() should set an end_time variable. stopTimer() can then subtract the two times and you've got the number of milliseconds passed. (JavaScript stores times in milliseconds, so oldTime - newTime = milliseconds passed.)

The following may help you getting started:

var lastClicked = 0;

function onClickCheck() {
    var timeNow = (new Date()).getTime();

    if (timeNow > (lastClicked + 5000)) {
        // Execute the link action
    else {
        alert('Please wait at least 5 seconds between clicks!');

    lastClicked = timeNow;


<a href="#" onClick="onClickCheck();">click here</a>

jQuery: Time between the two click events on a paragraph , Use the timeStamp property of the event object. e.g. (function() { var Clicks = 0, lastTimeStamp; function buttonClickHandler(ev) { var elapsed; Clicks++; if (Clicks >  console.time('function'); //run the function in between these two lines for that you need to //measure time taken by the function. ("ex. function();") console.timeEnd('function'); this is the most efficient way : using , e.g.

  1. Create a variable to hold the time of a click, say lastClick.
  2. Set up a click handler for the element you want to track clicks on.
  3. Inside the handler, check for a value in lastClick. If there is no value, set it to the current time. If there is a value, compare it against the current time. If the difference is within the range you're checking for, display the alert.

Is there anyway to accurately count time between clicks in javascript , click here. </ button >. < p id = "GFG_DOWN" style = "color: green; font-size: 24px; font-weight: bold;" >. </ p >. <!-- Script to calculate difference between two  How to use radio buttons in a calculation. In order to use radio buttons in a calculation, we need to give the radio buttons a name. All the radio buttons that belong to the same group should have the same name. This way, if you had more than one group of radio buttons, the code can distinguish which groups go with each other.

Start with var lastClicked = (new Date()).getTime(); //not zero

How to calculate minutes between two dates in JavaScript , Approach 1: Define two dates using new Date(). Calculate the time difference of two dates using date2.getTime() – date1.getTime();; Calculate  See the Pen JavaScript - Get time differences in minutes between two dates-date-ex-44 by w3resource (@w3resource) on CodePen. Improve this sample solution and post your code through Disqus. Previous: Write a JavaScript function to add specified months to a date. Next: Write a JavaScript function to get time differences in hours between two dates.

How to calculate the number of days between two dates in javascript , It would be dangerous to perform other time-intensive computations since you might Clicks on the button cause that handler to run, but clicks on the rest of the If two clicks happen close together, a "dblclick" (double-click) event also fires, code/squareworker.js that responds to messages by computing a square and  Free calculator to get the number of hours, minutes, and seconds between two times. In addition, a comprehensive version is included for calculating the time duration between two different dates. Also explore more calculators related to time, date, and many other topics.

Handling Events :: Eloquent JavaScript, var elapsed = new Date().getTime() - start;. This will give you the time taken between the two points in time in milliseconds. The Duration Calculator calculates the number of days, months and years between two dates.

Get the milliseconds with Javascript and measure time, Let's say, one part of our code wants to highlight a button on click, and another one wants to We'd like to assign two event handlers for that. Unfortunately, calculating a date interval such as days, weeks, or months between two known dates is not as easy because you can't just add Date objects together. In order to use a Date object in any sort of calculation, we must first retrieve the Date's internal millisecond value, which is stored as a large integer.