Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select all form elements?

Tags:

jquery

I usually just do this:

   $("#formid input, #formid select, #formid textarea")

But is there any shorthand for this, like..

   $("#formid All-Form-Elements")

?

like image 859
Control Freak Avatar asked Dec 26 '11 10:12

Control Freak


2 Answers

You seem to be looking for the :input selector:

var formElements = $("#formid :input");

Note that it also matches <button> elements.

like image 67
Frédéric Hamidi Avatar answered Nov 15 '22 11:11

Frédéric Hamidi


Use the :input selector, which selects all <input>, <textarea>, <select> and <button> elements.

$("#formid :input")
like image 40
Rob W Avatar answered Nov 15 '22 10:11

Rob W