onclick try code example
Example 1: button functions html
<script>
function myFunction() {
alert("ALERT");
}
</script>
<button onclick="myFunction">Click</button>
Example 2: javascript onclick button
var button = document.querySelector('button');
button.onclick = function() {
//do stuff
}