Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use jquery to select all inputs, that are not submit, reset or button?

I'm trying to select all input elements except input type="submit/reset/button

I have tried to make a selector like this:

inputSelector = 'input:not(input[type=button], input[type=submit], input[type=reset]), textarea, select'; 

But this does not work, because the submit buttons always make into the final selection.

Any idea what's wrong with the above.

Thanks!

like image 937
frequent Avatar asked Feb 16 '12 23:02

frequent


People also ask

Which is the correct jQuery selector to select all button elements and input elements with Type button?

The :button selector selects button elements, and input elements with type=button.


1 Answers

Try modifying your selector to chain .not(...) like:

var inputs = $('input, textarea, select')                 .not(':input[type=button], :input[type=submit], :input[type=reset]');  $(inputs).each(function() {     console.log(this.type); }); 

This makes it (arguably) easier to read, and should work how you expect.

like image 183
Michael Robinson Avatar answered Sep 20 '22 18:09

Michael Robinson