html js button click code example
Example 1: javascript button onclick
document.getElementById('button').onclick = function() {
alert("button was clicked");
};
Example 2: click button javascript
// Create variable for what you are trying to click
let button = document.querySelector("#IDofItem");
// Click the button
if (button) {
button.click();
}
else {
console.log("Error");
}
Example 3: calling function on click html
<img src="hospital.png" id="hospitals" onclick="damarkers();">