Why does my jquery function runs twice on click ?
$("a").click(processAction);
function proce开发者_Python百科ssAction(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 !
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.
.unbind("click").bind("click, somefunction) works beautifully.
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.
精彩评论