views:

761

answers:

3

I have an array of different elements stored from a previous selection, call it 'a'.

How do i then do another select from this previous selection (a) and just return elements of type input?

A: 
$(a).find("input")
Josh Stodola
If `a` comes from previous jQuery selection there is no need to wrap it around `$()`.
RaYell
find will not work as it searches descendant elements, these are all level 1 elements.
maxp
I started answer with filter function, then edited and changed to find, because your question was not clear.
Josh Stodola
+1  A: 
$('input', a);
RaYell
This doesnt do anything.
maxp
This searches input tags among the descendants of `a` and it works.
RaYell
I think it's $('input', 'a');
rball
No, it's not. `a` is a jQuery object as stated in the question.
RaYell
+4  A: 
a.filter('input').each(function() {
    alert('My name is ' + $(this).attr('name'));
});

To just get a selection from the current selection this way:

var $inputs = a.filter('input');

You can even comma separate selectors:

var $els = a.filter('input, .fooMonger, #something');

See http://docs.jquery.com/Traversing/filter

karim79
Thanks! I woulod give you more upvotes if i could.
maxp