Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

onclick event

onclick event

Event Object Reference Event Object

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

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:, ,
, , ,