In JQuery, how can i get list of input type with name, id and value present in any div?
Selects inputs that descend from a div that have both name, id, and value attributes present. Then pushes the "type" attribute of each matching item into an array.
var inputTypes = [];
$('div input[name][id][value]').each(function(){
inputTypes.push($(this).attr('type'));
});
http://api.jquery.com/multiple-attribute-selector/
In JQuery, how can i get list of input type...
This?
var inputTypes = [];
$('input[name!=""][value!=""][id!=""]').each(function() {
inputTypes.push($(this).prop('type'));
});
The property!=""
is necessary than just [property]
, this is to filter out things like
<input type="text" name="something" value="" id="someId" />
(Which I assume you don't want to get input with any property equals to empty string)
You can look at each input, get their attributes and check against an empty string for each. You could use any method you want to present them, here I'm just adding them to an array.
var inputs = new Array();
$("input").each(function() {
var name = $(this).attr("name");
var id = $(this).attr("id");
var val = $(this).val();
if ((name) && name !== "") && ((id) && id !== "") && ((val) && val !== "")) {
inputs.push(this);
}
});
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