Hello Readers,
Their are many ways in javascript and jquery where we can trigger an event using Id or Class. Here's the example of how we can trigger the event using "addEventListener()" method.
Let's suppose we have have button having id="myBtn".
<button id="myBtn">Try it</button>
<script>
document.getElementById("myBtn").addEventListener("click", displayDate);
function displayDate() {
document.getElementById("demo").innerHTML = Date();
}
</script>
When id="mybtn" is call it will trigger click function of addEventListener where it will redirect to displayDate function and display the current date and time in innerHtml of "demo" id.
<p id="demo"></p>
0 Comment(s)