By using this site you agree to the use of cookies and related technologies.

Learn more

OnClick - HTML Event Attribute

The OnClick event attribute controls what happens if a HTML element is clicked.

Created: 2016-10-04 12:11

The onClick event attribute is used to catch the click event of a pointing device.

The onClick attribute can be used to determine when a HTML element is clicked, which makes it possible to turn ordinary elements into clickable buttons. Doing this can however present usability issues, so it may be best to avoid using it on anything else than links and buttons.

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>