javascript onclick
document.getElementById("myBtn").addEventListener("click", function() {
alert("Hello World!");
});
NU
<button onclick="myFunction()">Click me</button>
<p id="demo"></p>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "Hello World";
}
</script>
NU
// The element id (TheElementID) and var name (myElement) can be named anything.
var myElement = document.getElementByID('TheElementID');
myElement.onclick = function() {
// Carry out a function here...
}
бутон javascript onclick
document.getElementById('button').onclick = function() {
alert("button was clicked");
};