Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

select all inputs except hidden (but with one exception)

Lets say I have a set of inputs on a form:

<form id="myform">
  <input type="checkbox" id="goat_1">
  <input type="checkbox" id="goat_2">
  <input type="text" id="pig_3">
  <input type="hidden" id="cow_1">
  <input type="hidden" id="chick_3">
  <input type="hidden" id="duck_5">
</form>

I want to select all inputs, except type="hidden", but with one exception I DO want any hidden input with an id beginning with "duck". I need this all in one array so I can iterate through it.

So the first two parts are easy:

$("#myform").find(":input").not("[type=hidden]").each(
                                          function () { alert("do stuff"); })

But what about the exception?

I am looking for the cleanest way to do this (prefer one line/statement).

like image 629
EkoostikMartin Avatar asked Aug 22 '13 01:08

EkoostikMartin


1 Answers

Try

$("#myform").find(":input").not("[type=hidden]:not([id^='duck'])").each(function () {
    alert("do stuff"); 
});
like image 53
Musa Avatar answered Oct 21 '22 19:10

Musa