0% found this document useful (0 votes)
15 views

HTML Body P P Button Button P P Script

The document contains HTML and JavaScript code that displays the current date as a string when a button is clicked. It defines a function called myFunction that gets the current date as a Date object, converts it to a string using toLocaleDateString(), and inserts it into a paragraph with id="demo". Clicking the button calls this function, displaying the formatted date.

Uploaded by

Dario Fazio
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

HTML Body P P Button Button P P Script

The document contains HTML and JavaScript code that displays the current date as a string when a button is clicked. It defines a function called myFunction that gets the current date as a Date object, converts it to a string using toLocaleDateString(), and inserts it into a paragraph with id="demo". Clicking the button calls this function, displaying the formatted date.

Uploaded by

Dario Fazio
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

26/1/2021 Tryit Editor v3.

     Run »

<!DOCTYPE html>
Click the button to display the date as a string.
<html>
<body> Try it

<p>Click the button to display the date as a string. 22/1/2021


</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction() {
var d = new Date();
var n = d.toLocaleDateString();
document.getElementById("demo").innerHTML = n;
}
</script>

</body>
</html>

https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_tolocaledatestring 1/1

You might also like