onclick

The onclick attribute specifies some script to run when the element is clicked.

Examples

Click on a <p> element to change its text color to red:

<p id="demo" onclick="myFunction()">Click me to change my text color.</p>

<script>
function myFunction() {
  document.getElementById("demo").style.color = "red";
}
</script>

onchange

The onchange event occurs when the value of an element has been changed. For radiobuttons and checkboxes, the onchange event occurs when the checked state has been changed.

Tip: This event is similar to the oninput event. The difference is that the oninput event occurs immediately after the value of an element has changed, while onchange occurs when the element loses focus, after the content has been changed. The other difference is that the onchange event also works on <select> elements.

Examples

Execute a JavaScript when a user changes the content of an input field:

<input type="text" onchange="myFunction()">

Contributions