JavaScript onclick Event Tutorial

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:

Take Your Free Live Demo Class Now

We Will Call Back You Shortly

Enter Your DETAILS BELOW

We Will Send You the Course Fees Details In Below Number

Enter Your DETAILS BELOW

We Will Call Back You Shortly

Enter Your DETAILS BELOW

We Will Call Back You Shortly

Enter Your DETAILS BELOW

Enter Your DETAILS BELOW TO take

free demo class