Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery select all Input except type hidden

I am selecting all inputs in jquery, like this:

$('input').each(function() {
...
});

But is it possible to create an exception like saying select all inputs with the exception of input type hidden.

I know that I could select input with the specific types I need but that does not look that good I think

Edit: sorry made the wrong example, I mean something like this:

document.forms["product"].getElementsByTagName("input");

with the exception of hidden

like image 324
John Does Legacy Avatar asked Oct 16 '25 01:10

John Does Legacy


2 Answers

Try this : you can make use of :not with [type="hidden"]

$(function(){
  $('input:not([type="hidden"])').each(function(){
    alert($(this).val());
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input value="1">
<input type="radio" value="2">
<input type="hidden" value="3">
<input type="checkbox" value="4">
like image 135
Bhushan Kawadkar Avatar answered Oct 18 '25 21:10

Bhushan Kawadkar


There are various method to use. I would prefer to use:

$('input:visible').each();

Notice: :visible does not select the input with the type="hidden".

Or you may use a little longer method:

$('input:not([type="hidden"]').each();

Or,

$('input').not('[type="hidden"]').each();

API References: visible-selector, not-selector, not

like image 22
Bhojendra Rauniyar Avatar answered Oct 18 '25 21:10

Bhojendra Rauniyar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!