To use a HTML button to call a JavaScript function, we add a click event handler to it.
For instance, we write
<input id="clickMe" type="button" value="clickme" />
to add a button.
Then we write
document.getElementById("clickMe").onclick = () => {
alert("hello!");
};
to select the button with getElementByid
.
And we set its onclick
property to a function that shows an alert box that shows hello! when we click the button.