How to trigger event in JavaScript?



The trigger() method triggers the specified event and the default behaviour of an event (like form submission) for the selected elements.

For example: 

$( "#foo" ).on( "click", function() {
  alert( $( this ).text() );
});
$( "#foo" ).trigger( "click" );
Updated on: 2019-10-03T06:38:20+05:30

823 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements