JavaScript - - By Sam Deering

jQuery simulate a toggle event

Using jQuery to “trigger” simulate a toggle event you can simply trigger a click event like this:


Then say if you have 2 buttons which do exactly the same thing you can simulate a click on the button with the event handler attached to promote code reuse.

//simulate an event
$(this).parents('.parent').find('.controls cancel').trigger('click');