KJW
KJW

Reputation: 15251

Jquery: function runs twice

Why does my jquery function runs twice on click ?

$("a").click(processAction);

function processAction(e){
    var clicked = e.target;

//show apply button.

        $("#apply").live("click",function(e){
            e.stopPropagation();
            someFunction(clicked);
            alert("this the array " + mydata);
                clicked = "";
            }); 
}   

someFunction is running twice !

Upvotes: 2

Views: 3401

Answers (3)

KJW
KJW

Reputation: 15251

.unbind("click").bind("click, somefunction) works beautifully.

Upvotes: 3

bcm
bcm

Reputation: 5500

If you are using .live() to attach the click event to that specific anchor, you don't have to attached another click event to the anchor using

$("a").click(processAction);

I'm not sure if it's intentional that you are putting the .live in the anchor click function, if it is not, you can pull out the .live() and seperate from the actual click function.

Upvotes: 0

Thomas
Thomas

Reputation: 2162

For every click on an a-element, you add a click handler to your #apply-element. If you click 3 times on an a-element, then click on #apply, three different instances of 'someFunction' will run.

Upvotes: 6

Related Questions