Execute a JavaScript when a button is clicked:
The onclick event occurs when the user clicks on an element.
In HTML:
In JavaScript:
| Parameter | Description |
|---|---|
| SomeJavaScriptCode | Required. Specifies a JavaScript to be executed when the event occurs |
![]()
The onclick event is supported in all major browsers.
The onclick attribute can be used within ALL HTML elements, EXCEPT: <base>, <bdo>, <br>,
<head>, <html>, <iframe>, <meta>, <param>, <script>, <style>,
and <title>.
Event Object
Your message has been sent to W3Schools.