pasluc74669
pasluc74669

Reputation: 1700

How to find an element in an array by attribute in jQuery

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

Answers (5)

Edward
Edward

Reputation: 1914

Please try using .find()

el = $('#clienti-table input:not(#additionalAds)').find('#id');

http://api.jquery.com/find/

Upvotes: 0

Faust
Faust

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

Musa
Musa

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

jcreamer898
jcreamer898

Reputation: 8189

Try this... $('#clienti-table input:not([id='additionalAds']));

Upvotes: 0

tymeJV
tymeJV

Reputation: 104775

You can use a for loop:

for (var i = 0; i < tableInputs.length; i++) {
    console.log(tableInputs[i].id);
}

Upvotes: 0

Related Questions