By using this site you agree to the use of cookies by Brugbart and our partners.

Learn more

JavaScript onclick Event

Reference on the onclick event of HTML and JavaScript, and example of how to use it with a user-made function.

Edited: 2013-07-18 12:53

The JavaScript onclick event catches the click event of an element. The onclick event works almost anywhere, and can be used to trigger user made JavaScript Functions, as well as build in functions.

JavaScript onclick example

The below shows how to use the onclick event on a button element, to throw out a basic alert box.

<button onclick="alert('Dont poke me. Just dont. Im just not in the mood!');">Don't poke me!</button>

See also

  1. Event Attributes