1

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.

2
  • 1
    Can you clarify what you want? Do you want an item with a specific id, or do you want a list of the ids? Do you want something else? Commented May 30, 2013 at 18:17
  • honestly, i think you should be able to find the element you want directly by the id unless you are using duplicated id somewhere else which is not a good practice at all. Commented May 30, 2013 at 18:22

5 Answers 5

1

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);
Sign up to request clarification or add additional context in comments.

Comments

0

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`

Comments

0

You can use a for loop:

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

Comments

0

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

Comments

0

Please try using .find()

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.