admin管理员组文章数量:1320661
I have the following line which works OK
$("#myDiv img:not(:eq(0))").hide();
I want to write a similar line but using "this". So:
$(this":not(:eq(0))").hide();
But that doesn't work... Any ideas where it's gone wrong?
I have the following line which works OK
$("#myDiv img:not(:eq(0))").hide();
I want to write a similar line but using "this". So:
$(this":not(:eq(0))").hide();
But that doesn't work... Any ideas where it's gone wrong?
Share Improve this question asked Mar 9, 2011 at 14:13 TomTom 13k50 gold badges153 silver badges247 bronze badges5 Answers
Reset to default 6try .not(selector)
http://api.jquery./not/
The other answers are forgetting an important point - this
is most likely in some event callback, and is likely a single element, so it is always the first element in the selection (:eq(0)
).
Therefore each the following equivalent snippets will never hide anything:
$(this).not(':eq(0)').hide();
$(this).filter(':gt(0)').hide();
$(this).slice(1).hide();
I am only guessing the OP's intent here, but the code should most likely be:
if ($(this).index('#myDiv img') > 0) $(this).hide();
Something like this should work:
$(this).not(":eq(0)").hide();
It seems like you should be using the :gt()
selector
Description: Select all elements at an index greater than index within the matched set.
try:
$(this).find(":gt(0)").hide();
or:
$(":gt(0)", this).hide();
isn't :not(:eq(0))
a clunky way of writing :gt(0)
?
$($(this).selector + ":not(:eq(0))").hide();
本文标签: javascriptUsing not selector with (this)Stack Overflow
版权声明:本文标题:javascript - Using :not selector with $(this) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742064208a2418735.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论