bhylu.com

Advertisements

Mouse Events

Click is useful for an action that should work with a mouse, touch, and keyboard activation. Mouse-only hover should not hide essential information.

Where to run this

This example changes a document. Open it in the HTML playground, then select Run code. It runs inside a separate preview.

A practical example

HTML + JavaScript

<button id="details" type="button">Show details</button>
<p id="message"></p>
<script>
  document.getElementById("details").addEventListener("click", event => {
    document.getElementById("message").textContent = "Activated " + event.currentTarget.textContent;
  });
</script>

What happens

The message names the activated button.