0

Guess there is two click event X and Y.

$('X').on('click',function(){
    //some function here
});

and

$('Y').on('click',function(){
    //this will run the X event
});   

Here,At the same time I don't have access of trigger X . So I need to run that function/event by clicking Y trigger.

Is it possible somehow?

Jim Fahad
  • 635
  • 1
  • 8
  • 21

2 Answers2

4

You are looking for trigger:

$('Y').on('click',function(){
   $('X').trigger('click'); 
});  
Perfect28
  • 11,089
  • 3
  • 25
  • 45
4

You can always use .trigger()

Execute all handlers and behaviors attached to the matched elements for the given event type.

$('Y').on('click',function(){
    $('X').trigger('click')
}); 

However, you can simply bind same event handler to both elements then you don't need to use the above method.

$('X, Y').on('click',function(){
    //Do something
});
Satpal
  • 132,252
  • 13
  • 159
  • 168