onclick Event
The onclick event occurs when the user clicks on an element.
Syntax
In HTML:
object.onclick = function(){myScript};
Example
In JavaScript:
object.onclick = function(){myScript};
More Examples
Click on an element to display the current day, date, and time:
Another example of how to change the color of a element by clicking on it: