tadam logo
Did you find an error in the text?
Select this with mouse and press
Ctrl + Enter
Xhtml.co.il Check Spelling
Orphus system

event.timeStamp

event.timeStamp

Returns: Number

Description: This attribute returns the number of milliseconds since January 1, 1970, when the event is triggered.

event.timeStamp

version added: 1.2.6

Example

Display the time since the click handler last executed.
var last, diff;
$('div').click(function(event) {
  if ( last ) {
    diff = event.timeStamp - last
    $('div').append('time since last event: ' + diff + '<br/>');
  } else {
    $('div').append('Click again.<br/>');
  }
  last = event.timeStamp;
}); 
The output of the code above will be:

Full source

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style>
      div { height: 100px; width: 300px; margin: 10px; 
      background-color: #ffd; overflow: auto; }
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
  <script type="text/javascript" language="javascript">
     $(document).ready(function(){
      var last, diff;
      $('div').click(function(event) {
      if ( last ) {
        diff = event.timeStamp - last
        $('div').append('time since last event: ' + diff + '<br/>');
      } else {
        $('div').append('Click again.<br/>');
      }
       last = event.timeStamp;
     }); 
  });
  </script>

</head>

<body>
  <div></div>
</body>

</html>
Was this information helpful?
   

Comments