Your issue doesn't actually have anything to do with the filter, it's
the selection. $('.class1,.class2') selects all class1, then all
class2. So even if class2 appears before class1, class one will still
get selected first (since you specified it first in the selector), and
your filter will return it.

I suggest you apply the same class to all elements that you want to
select from. If nothing else, you could do:

$('.class1,.class2').addClass('class1_or_class2');
$('.class1_or_class2').filter(':first')...;

And that second line could be simplified to:
$('.class1_or_class2:first')...;

Hope it helps.

--Erik


On 11/5/07, Pyrolupus <[EMAIL PROTECTED]> wrote:
>
> Basically, what I want to do is find the first element that matches
> either class1 OR class2.  However, using the syntax from the subject
> line:
>
>   var $jqElem = $('.class1,.class2').filter(':first');
>
> $jqElem is always the first element that has class1 (i.e., the first
> class specified), rather than the first element for the whole
> selector.  E.g., using the above on the following:
>
>   <input type="text" id="elem1" class="class2" />
>   <input type="text" id="elem2" class="class1" />
>
> it is getting "elem2."
>
> Am I using the wrong syntax?  I also tried $
> ('.class1').add('.class2').filter(':first'), but I get the same
> result.
>
> Thanks,
> Pyro
>
>

Reply via email to