Triggering events in vanilla JavaScript
So you want to trigger an event for a DOM element, without using jQuery? This blog post gives you a quick recipe for doing so. The running example is about sending a submit event to a form. I needed to do that for a demo of user interface testing via CasperJS . And, unfortunately, the Form#submit method does not send that event on most web engines. The recipe Steps: Look up the constructor of the event, via a table on MDN that maps event names to event constructors. Example: submit events are created via the Event constructor. Look up the arguments of the event constructor, via the drafts of the specifications for DOM4 and UI Events . Example: The constructor for interface Event has the following Interface Definition Language (IDL) signature: Constructor(DOMString type, optional EventInit eventInitDict) Optionally, EventInit can be passed in as an object and configures whether an event bubbles or is cancel...