Click on a <button> element to display the current day, date and time: - Javascript DOM Event

Javascript examples for DOM Event:onclick

Description

The onclick event occurs when the user clicks on an element.

Summary

Bubbles Yes
Cancelable Yes
Event type: MouseEvent
Supported HTML tags: All HTML elements, EXCEPT: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, and <title>

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p>Click the button to display the time.</p>

<button onclick="getElementById('demo').innerHTML=Date()">What is the time?</button>

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

</body>/*  w  w  w  . jav  a 2s  . co m*/
</html>

Related Tutorials