HTML <button> Tag with the 'onclick' Attribute

<button onclick="JavaScript:alert('Thanks!')">
Click Me

Here, we add JavaScript to a button via the onclick event handler content attribute to make the button actually do something). The onclick event handler is invoked when the user clicks on the button.

About the <button> Element

The <button> element creates a button control in an HTML document.

Any contents of the <button> element appears on the button.

The <button> element can be associated with a form or stand alone by itself (in such case it could have JavaScript attached via the onclick attribute — as we have done in the above example) to make the button actually do something.