Use the DOM to assign an onclick event to the <button> element. Clicking the button should trigger displayDate(). - Javascript DOM

Javascript examples for DOM:Quiz

Description

Use the DOM to assign an onclick event to the <button> element. Clicking the button should trigger displayDate().

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button id="myBtn">Try it</button>

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

<script>
document.getElementById("myBtn").onclick = function(){displayDate()};

function displayDate() {/* w  w  w .  ja  v a  2 s.  com*/
    document.getElementById("demo").innerHTML = Date();
}
</script>

</body>
</html>

Related Tutorials