spike.y
spike.y

Reputation: 399

When user clicks on one element, trigger a click on another.

I have some links on my page and I need to programmatically perform a click on an element when the user clicks on another element. For example, when I click on element A, jQuery should perform a click on element A2.

I don't know what this is called, technically, and I'm having trouble finding out how to do this. Is this possible in jQuery?

Upvotes: 0

Views: 84

Answers (3)

Pratik Joshi
Pratik Joshi

Reputation: 11693

Use following to do trigger event,When div1 is clicked , Trigger click event for div2

$("#div1").click(function (){ 
     $("#div2").trigger("click");
});

Working demo http://jsfiddle.net/MSSbT/

Upvotes: 2

mifi79
mifi79

Reputation: 1106

Attached an event handler to your first element (#elementA in the example below) and then trigger a click event on the second element (#elementB below)

$("#elementA").on("click", function (e) {
     $("#elementB").click();
});

Here is the Fiddle: http://jsfiddle.net/mifi79/Dar8J/

Upvotes: 3

user3696176
user3696176

Reputation: 31

You can trigger a click via click()

http://api.jquery.com/click/#click

Upvotes: 1

Related Questions