tags:

views:

87

answers:

2

How do I manually fire a click event on a button that I previously wired up using jQuery?

+6  A: 

Use Trigger. (link to documentation for trigger)

$("button:first").click(function () {
  update($("span:first"));
});
$("button:last").click(function () {
  $("button:first").trigger('click');

  update($("span:last"));
});

function update(j) {
  var n = parseInt(j.text(), 10);
  j.text(n + 1);
}
altCognito
fast on the trigger there!
Russ Cam
that's the punniest thing I read all day! :)
altCognito
+1  A: 

One way I've done it is:

$('#pSearch').click();

The pSearch is the ID of the button I want to click.

Poldon