onclick event
Example
Execute JavaScript code when a button is clicked:
Try it »
Definition and Usage
The onclick event occurs when an element is clicked.
Syntax
In HTML:
<
element
onclick="
SomeJavaScriptCode
">In JavaScript:
object
.onclick=function(){
SomeJavaScriptCode
};
| Parameters | Description |
|---|---|
| SomeJavaScriptCode | Required. Specifies the JavaScript to be executed when the event occurs. |
Browser support





All major browsers support the onclick event
HTML tags that support the onclick event:
The onclick attribute can be used on all HTML elements, except:
, , ,
Event Object