<button id="myBtn">Try it</button> <p id="demo"></p> <script> document.getElementById("myBtn").onclick=function(){displayDate()}; function displayDate() { document.getElementById("demo").innerHTML=Date(); } </script>