Simmi Badhan
Simmi Badhan

Reputation: 533

Is it possible to trigger two click events consecutively in one function in jQuery?

On a certain event, I want to trigger a click event that loads a tab and then trigger another click event on a button on the tab consecutively.

Is it possible to trigger two click events in sequence? When I try doing so, the second one doesn't work.

Upvotes: 0

Views: 1307

Answers (2)

Rohan Kumar
Rohan Kumar

Reputation: 40639

Yes you can by using trigger() like,

$('#button1').click(function() {
    $('#tab,#button2').trigger('click');// trigger click of two elements
    // $('#tab,#button2').click();// use click() directly
});

Upvotes: 4

Hamza Kubba
Hamza Kubba

Reputation: 2269

$('#button1').click(function() {
    // do something here
});

$('#button2').click(function() {
    // do something else here

    // then simulate clicking the other thing:
    $('#button1').click();
});

Upvotes: 2

Related Questions