how does button onclick works in javascript mdn code example
Example 1: javascript button onclick
document.getElementById('button').onclick = function() {
alert("button was clicked");
};
Example 2: html js button onclick
// In HTML:
// <button id="buttonID" onclick="yourJSFunction()">Text</button>
// In JavaScript:
function yourJSFunction() {
// Do stuff
}