views:

200

answers:

4

Is there a way to trigger a hidden button on an html markup page using jquery or jscript?

How would I do that if possible?

Thank you,

James

+2  A: 
$('#example-button-id').click();
Ken Browning
This looks good, I shall give it a try.Thank you Ken!
James
A: 

If I understand correctly, you want to fire an event programmatically. This is usually not necessary. You can very easily move the button click even code to a new method, and have the event invoke that method. You can then also call the method in the code that would want to fire the button click even programmatically.

Matthew Vines
+3  A: 

With jQuery:

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

or:

$('#buttonId').trigger('click');

With plain JavaScript:

document.getElementById('buttonId').onclick();

Since you're using ASP .NET you might want to get the button id by using the ClientID server-side property of the control:

$('#<%=Button.ClientID %>').click();

Or:

document.getElementById('<%=Button.ClientID %>').onclick();
CMS
Thanks CMS for the additional info on this..
James
I went with this one: $('#<%=Button.ClientID %>').click();Thank you
James
You're welcome @James
CMS
A: 

Try this (requires jquery):

$("button").trigger('click');
Steerpike