In this tutorial, we are going to discuss the button click event.
We can directly call a function on onclick event in HTML tag.
Let's see the below example.
1. Directly call event in tag 'onclick'
<button onclick="alert('alert')">Click to alert</button>
Also, We can fire click event by refrencing element.
Let's see the below example.
2. By selecting element
<button id="btn">Click to alert</button>
<script>
let btn = document.getElementById('btn');
btn.addEventListener("click",()=>{
alert("clcked");
})
</script>
0 Comments
If you have any question please ask?