1$( "#foo" ).on( "click", function() {
2 alert( $( this ).text() );
3});
4$( "#foo" ).trigger( "click" );
5
6$( "#foo" ).on( "custom", function( event, param1, param2 ) {
7 alert( param1 + "\n" + param2 );
8});
9$( "#foo").trigger( "custom", [ "Custom", "Event" ] );
1// On mouse-over, execute myFunction
2function myFunction() {
3 document.getElementById("myCheck").click();
4}
5
1const body = document.body;
2
3body.addEventListener('click', e => {
4 console.log('clicked body');
5});
6
7console.log('Using click()');
8body.click();
9
10console.log('Using dispatchEvent');
11body.dispatchEvent(new Event('click'));
1<form>
2 <input type="checkbox" id="myCheck" onmouseover="myFunction()" onclick="alert('click event occurred')">
3</form>