Reputation: 1700
I need help finding an object in an array of jQuery selectors by attribute.
This is the code used for selection of the inputs elements in a table:
var tableInputs = $('#clienti-table input:not(#additionalAds)');
In variable tableInputs
there are 13 input elements. I need to find each element by the id attribute.
Is there any way to do it?
Hope someone can help me.
Thanks in advance.
Upvotes: 1
Views: 363
Reputation: 1914
Please try using .find()
el = $('#clienti-table input:not(#additionalAds)').find('#id');
Upvotes: 0
Reputation: 15394
You can loop over the colleciton with .each()
:
tableInputs.each(function(){
var elem = this; //do something with this.
var id = elem.attr('id');
});
Or you can extract an element with a particular id, like this:
var $myElem = tableInputs.find('#myId');
... or by specifying the context in which to look for your element, like this:
var $myElem = $('#myId', tableElements);
Upvotes: 1
Reputation: 97672
You can use filter
to get the element with a given id.
tableInputs.filter('#'+someid);// this gives you the element in the selection with id `someid`
Upvotes: 0
Reputation: 8189
Try this... $('#clienti-table input:not([id='additionalAds']));
Upvotes: 0
Reputation: 104775
You can use a for loop:
for (var i = 0; i < tableInputs.length; i++) {
console.log(tableInputs[i].id);
}
Upvotes: 0