Is eq the correct selector to get the first element of a jquery list? It gives me an error
I try to get the first .myClass element of my page.
To do that, I use $(".myClass:eq(0)");
This is working perfectly but gives me the following console error:
"Warning: Pseudo-class or pseudo-element "eq" unknown."
(Traduced from french)
Is that error normal? Is there a way to avoid it? Which syntax do you use to select first开发者_如何学Go elements? I also tried $(".myClass:first");
but the problem is then the same with first.
Thank you in advance for your help David
Your code is fine and correct. I'm wondering which jQuery version you are using and on what browser you are testing.
$(".myClass").first()
which is a shortcut for
$(".myClass").eq(0)
might solve your trouble. .first() will not use sizzle
to query elements, but uses array slice
to reduce the set of matched elements.
you are getting this warning because eq()
is not a valid css selector...
you are getting the same with :first
because the :first
pseudo-class is equivalent to :eq(0)
..
and jQuery catches this warning, and then do the thing it needs to do with it...
just same with this :hidden
精彩评论