The DOM lastModified property in HTML is used to return the date and time of the current document that was last modified. This property is read-only. This property returns a string that contains the date and time when the document was last modified.Â
Syntax
document.lastModifiedExample: In this example, we will use the lastModified property
<!--Driver Code Starts-->
<!DOCTYPE html>
<html>
<head>
<title>
DOM lastModified Property
</title>
</head>
<body style="text-align:center">
<h1 style="color:green;">
GeeksForGeeks
</h1>
<h2>
DOM lastModified Property
</h2>
<!--Driver Code Ends-->
<button onclick="geeks()">
Submit
</button>
<p id="sudo"></p>
<script>
/* Function to use lastModified property */
function geeks() {
let x = document.lastModified;
document.getElementById("sudo").innerHTML = x;
}
</script>
<!--Driver Code Starts-->
</body>
</html>
<!--Driver Code Ends-->
- The code uses the
document.lastModifiedproperty to get the date and time when the current HTML document was last modified and displays it inside the<p>element. - The
geeks()function runs when the Submit button is clicked, retrieves the last modified date, and updates the webpage content usinginnerHTML.