You are here

jQuery Toggle Firing Twice

When trying to toggle an element on a page using jQuery, you might have the toggle happen multiple times. In other words, you click the event listening element (such as a link) and the element you want to toggle expands and collapses, then once more expands and collapses. Obviously, this is not the effect we are going for.

The reason seems to be that the element was bound more than once so it fires once for each binding. The solution is to unbind the element before calling the toggle.

$(".toggle_action_items").unbind().on('click', 'a', function (e) {
	$("#the_id").slideToggle(100, function () { });

Unbinding it before calling the listener will clear the bindings and then run the listener.

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
3 + 2 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer