onclickEvent

事件对象参考手册Event Object

Examples

Execute JavaScript code when the button is clicked:

<button onclick="myFunction()">Click me</button>

Try it Yourself »

Definition and Usage

The onclick event occurs when an element is clicked.

Syntax

In HTML:

<element onclick="SomeJavaScriptCode">

In JavaScript:

object.onclick=function(){SomeJavaScriptCode};

Parameter Description
SomeJavaScriptCode Required. Specifies the JavaScript to execute when the event occurs.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, and <title>.


事件对象参考手册Event Object Other Extensions