I have a function bound to a button that looks like this:

$(".deletebutton").click(function(sender){...somecode...}

In another function (Let's call it function_2) i want do do the same thing that happenes in the click-funktion. Now i dont want to use

$( ".button" ).trigger( "click" );

because within the click-function i have to distinguish, if the function is called by pressing the button or by calling it in function_2.

Can anyone help me there?

Note: Sorry if the title may be misleading, i didnt know how to say it better in english!

有帮助吗?

解决方案

You can isolate your function. In this case you will be able to call it onclick and on any other event. Something like this:

function someName(){...somecode...}

$(".deletebutton").click(someName());

function function_2(){
   ...some code...
   someName();
   ...some code...
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top