0

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?

Abijeet Patro
  • 2,842
  • 4
  • 37
  • 64
spike.y
  • 389
  • 5
  • 17

3 Answers3

3

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/

mifi79
  • 1,086
  • 6
  • 8
2

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/

Pratik Joshi
  • 11,485
  • 7
  • 41
  • 73
1

You can trigger a click via click()

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