Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery: function runs twice

Tags:

jquery

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 !

like image 895
KJW Avatar asked Feb 27 '26 19:02

KJW


2 Answers

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.

like image 151
Thomas Avatar answered Mar 01 '26 08:03

Thomas


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

like image 34
KJW Avatar answered Mar 01 '26 08:03

KJW



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!