🔥 Get 650+ Tech Books and Courses for $3/m for 3 months

jQuery simulate a toggle event

Sam Deering

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');