click() event is calling twice in jquery - madhusudana30/AlternativeJPAForWebSphere GitHub Wiki

stackoverflow.com/questions/6731894/click-event-is-calling-twice-in-jquery

$(“#link_button”) .button() .click(function () {

$("#attachmentForm").slideToggle("fast");

});

Make sure and check that you have not accidentally included your script twice in your HTML page.

$(“#link_button”).unbind(‘click’); $(“#link_button”) .button() .click(function () {

$("#attachmentForm").slideToggle("fast");

});

webroxtar.com/2011/10/solution-jquery-click-event-gets-called-twice-fires-twice/

The Solution: Find out the duplicate places where you have attached the same event handler to the same element and remove them. If they are necessary and removing them is not an option for example if you are creating the elements dynamically or you can’t find where and how this duplication occurs then first unbind the handler and then rebind again, so that previously bound handler will get cancelled. Below is the example code:

JavaScript $(“.button”).unbind(‘click’).click(

function()
{
    alert('I am the alert from the click event handler');
}

); 1 2 3 4 5 6 $(“.button”).unbind(‘click’).click(

function()
{
    alert('I am the alert from the click event handler');
}

); or

JavaScript $(“.button”).unbind(‘mousedown’).mousedown(

function()
{
    alert('I am the alert from the mousedown event handler');
}

); 1 2 3 4 5 6 $(“.button”).unbind(‘mousedown’).mousedown(

function()
{
    alert('I am the alert from the mousedown event handler');
}

);

⚠️ **GitHub.com Fallback** ⚠️