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
2009-04-30 20:58:09
fast on the trigger there!
Russ Cam
2009-04-30 20:58:46
that's the punniest thing I read all day! :)
altCognito
2009-04-30 21:26:25
+1
A:
One way I've done it is:
$('#pSearch').click();
The pSearch is the ID of the button I want to click.
Poldon
2009-04-30 20:59:09