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
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">
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With