HTML onclickEvent Attribute

HTML 事件属性HTML Event Attribute

Example

Run script when the mouse is clicked:

<button onclick="copyText()">Copy Text</button>

Try it Yourself »

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the onclick event attribute


Definition and Usage

The onclick attribute triggers when the mouse is clicked.

Note:The onclick attribute cannot be applied to the following elements: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, or <title>.


Differences between HTML 4.01 and HTML5

None.


Syntax

<element onclick="script">

Attribute Values

Value Description
script Specifies the script to be executed when the onclick event is triggered.


HTML 事件属性HTML Event Attribute Other Extensions