Reputation: 651
I have one event as,
$('#load').click(function(){
// do something
});
then I have other event in which I want to call above event, how can I do that? Other event :
$('#save').click(function(){
//do something related to save
//then call $('#load').click() event in side this
});
Upvotes: 1
Views: 918
Reputation: 1763
The trigger() function is the solution for your problem. You can use it as follows
$('#load').click(function(){
// do something
});
$('#save').click(function(){
//do something related to save
$('#load').trigger('click');
});
Here what the code says is when you click on save it runs through your save.click event and then trigger the load.click event. You can change use any other event inside trigger() function to do trigger some other events related to "#load" element.
For more information your can refer http://api.jquery.com/trigger/
Upvotes: 0
Reputation: 26
Click to #load from #save.click
$('#save').click(function(){
$('#load').click()
});
Upvotes: 0
Reputation: 160983
$('#save').click(function(){
//do something related to save
//then call $('#load').click() event in side this
$('#load').click(); // or $('#load').trigger('click');
});
Upvotes: 1
Reputation: 1420
How about just try to use your $('#load').click() event code?
Just like, when:
$('#save').click(function(){
// Code from $('#load').click() event in side this
});
Upvotes: -1
Reputation: 11235
You can do it like this:
$('#load').click(function(){
make();
});
$('#save').click(function(){
make();
});
function make(){
}
Upvotes: 1