Reputation: 266988
How do I manually fire a click event on a button that I previously wired up using jQuery?
Upvotes: 0
Views: 1188
Reputation: 11
Youe can use an ID or class name as a selector to select the element
Then you can do it as below
$(".className").click();
$("#ID").click();
it works with me and you can try it in chrome console
Upvotes: 0
Reputation: 365
One way I've done it is:
$('#pSearch').click();
The pSearch is the ID of the button I want to click.
Upvotes: 1
Reputation: 41381
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);
}
Upvotes: 6