Open In App

jQuery event.timeStamp Property

Improve
Improve
Like Article
Like
Save
Share
Report

The jQuery event.timeStamp is an inbuilt property that is used to measure the difference in milliseconds between the time of the event created by the browser and January 1, 1970. 

Syntax:

event.timeStamp

Parameter: It does not accept any parameter because it is a property, not a function. 

Example 1: This Example shows the working of an event.timeStamp property.

HTML




<!DOCTYPE html>
<html>
 
<head>
    <script src=
    </script>
    <script>
        //jQuery code to show the working
        // of event.timeStamp property
        $(document).ready(function () {
            $("p").click(function (event) {
                $("span").text(event.timeStamp);
            });
        });
    </script>
    <style>
        p {
            width: 80%;
            padding: 20px;
            display: block;
            border: 2px solid green;
        }
    </style>
</head>
 
<body>
    <!-- click on this paragraph -->
    <p>The click event occurred
        <span style="color:green">
            unknown
        </span>
        milliseconds after January 1, 1970.
    </p>
</body>
 
</html>


Output:

Example 2: In this example, a pop-up will show how many milliseconds click event occurred after January 1, 1970.

HTML




<!DOCTYPE html>
<html>
 
<head>
    <script src=
    </script>
    <script>
        < !--jQuery code to show the working
            of event.timeStamp property-- >
        $(document).ready(function () {
            $("div").click(function (event) {
                alert(event.timeStamp + " milliseconds");
            });
        });
    </script>
    <style>
        div {
            width: 40%;
            padding: 20px;
            display: block;
            border: 2px solid green;
            font-size: 2em;
        }
    </style>
</head>
 
<body>
    <center>
        <!-- click inside the box -->
        <div>Geeksforgeeks</div>
    </center>
</body>
 
</html>


Output:



Last Updated : 07 Jul, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads