🤩 Get 50% off a full stack of courses and books

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