Latest web development tutorials

HTML onclick event attribute

HTML Event Attributes HTML Event Attributes

Examples

Run the script when you click the mouse:

<button onclick="copyText()">复制文本</button>

try it"

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the onclick event attribute


Definition and Usage

onclick attribute trigger when you click the mouse.

Note: onclick attribute can not 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

no.


grammar

<elementonclick=" script ">

Property Value

描述
script 规定该onclick事件触发时执行的脚本。


HTML Event Attributes HTML Event Attributes