JQuery Select Input Fields Except Hidden
$(":input:not([type=hidden])")
":input" is a jQuery pseudo selector... "Selects all input, textarea, select and button elements." http://api.jquery.com/input-selector/
Assuming by "hidden" you mean type="hidden"
ie:
<input type="hidden" name="foo" value="bar">
then you can use the attribute not equals selector to do this:
$("tr input:checkbox").click(function() {
var cb = $(this);
var tr = $(this).closest("tr");
if (cb.val()) {
tr.find("input[type!='hidden']").attr("disabled", true);
} else {
tr.find("input[type!='hidden']").removeAttr("disabled");
}
});
My general advice is avoid attribute selectors. They're slow. Give the relevant inputs (either the hidden ones or the not hidden ones) a class and then use that in the selectors.
If however you mean "hidden" as in "not visible" then use the :visible
selector:
$("tr input:checkbox").click(function() {
var cb = $(this);
var tr = $(this).closest("tr");
if (cb.val()) {
tr.find("input:visible").attr("disabled", true);
} else {
tr.find("input:visible").removeAttr("disabled");
}
});
You can also solve this using the hidden selector
$("input:not(:hidden)")
See also: jQuery hidden selector
I found a simple way of doing this in jquery.
$("tr input").not("input[type='hidden']")
In code snippet below, there is a div with an id of tabsDiv
that contains multiple html elements and this code gets all input elements inside this div except those with type of hidden
.
$("#tabsDiv").find("input").not("input[type='hidden']")