Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does jQuery's `click()` method work on hidden form elements?

Or, asked another way, do hidden form elements (<input type="hidden"... />) support jQuery's click() method?

like image 801
Jeromy French Avatar asked Jul 30 '13 19:07

Jeromy French


1 Answers

Yes, hidden inputs work with the click() method. You can't click on a hidden input element with your mouse, but you can execute the click event using the click method.

So, given this HTML:

<form>
    <input type="hidden" name="input1" id="input1" value="Yes">
</form>

You can assign a click handler:

$('#input1').click(function () {
    //do something
});

and invoke the click event:

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

See http://jsfiddle.net/jhfrench/v6LUd/ for a working example.

like image 117
Jeromy French Avatar answered Nov 07 '22 11:11

Jeromy French