Frage

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!

War es hilfreich?

Lösung

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...
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top