JavaScript
Article

jQuery simulate a toggle event

By Sam Deering

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

.trigger('click');

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

The HTML

No Reader comments

Recommended

Learn Coding Online
Learn Web Development

Start learning web development and design for free with SitePoint Premium!

Get the latest in JavaScript, once a week, for free.