Q:

Count the number of milliseconds between the two click events on a paragraph using jquery

0

Count the number of milliseconds between the two click events on a paragraph using jquery

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

HTML Code :

<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
 <meta charset="utf-8">
 <title>Count the number of milliseconds between the two click events on a paragraph</title>
 </head>
 <body>
 <p>Count the number of milliseconds between the two click events on a paragraph </p>
   <div>Click on the above paragraph</div>
   </body>
   </html>

JavaScript Code :

var lastt, tdiff;
$( "p" ).click(function( event ) {  if (lastt) {
  tdiff = event.timeStamp - lastt;
  $( "div" ).append( "Time since last event: " + tdiff + "<br>" );
   } 
   else {
     $( "div" ).append( "<br>Click again.<br>" );
	   }
	 lastt = event.timeStamp;
	});

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now