Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Button.click() event is triggered twice

I have the following problem with this code:

<button id="delete">Remove items</button>  $("#delete").button({      icons: {              primary: 'ui-icon-trash'      } }).click(function() {      alert("Clicked"); }); 

If I click this button, the alert show up two times. It's not only with this specific button but with every single button I create.

What am I doing wrong?

like image 438
user276289 Avatar asked Jun 18 '10 14:06

user276289


People also ask

Why is this jquery Ajax click event firing multiple times?

This happens because somewhere in your code, you're rebinding the event handler without first unbinding it.


1 Answers

In that case, we can do the following

$('selected').unbind('click').bind('click', function (e) {   do_something(); }); 

I had the event firing two times initially, when the page get refreshed it fires four times. It was after many fruitless hours before I figured out with a google search.

I must also say that the code initially was working until I started using the JQueryUI accordion widget.

like image 194
Simeon Abolarinwa Avatar answered Sep 21 '22 18:09

Simeon Abolarinwa