JavaScript onclick Event

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

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>

Post comment

Links that you insert are not nofollowed, but will be removed by admins if they are considered spam.

[url=Absolute URL for page]TITLE[/url]

You should insert code boxes around code examples, which will be automatically syntax highlighted.

[code1 html|css|javascript|php|sql]Your Code Here[/code1]

You may want to read our Privacy Policy before submitting your comment.