是否可以获取第 n 个子选择器的 .offset() ?
给出值时,我收到空错误
$('.art:nth-child(2)').offset();
由于某种原因,当我运行while
$('.art:first').offset()
并
$('.art:last').offset()
,没有问题。 offset() 只会返回第一个和最后一个子节点的值吗?
HTML:
<div class="row_titles">
<a href="#"><img class="art" src="images/channel_art/netflix-trainspotting.jpg" /></a>
<a href="#"><img class="art" src="images/channel_art/netflix-ronin.jpg" /></a>
<a href="#"><img class="art" src="images/channel_art/netflix-camelot.jpg" /></a>
<a href="#"><img class="art" src="images/channel_art/netflix-the_fighter.jpg" /></a>
<a href="#"><img class="art" src="images/channel_art/netflix-johnmalkovich.jpg" /></a>
<a href="#"><img class="art" src="images/channel_art/netflix-memento.jpg" /></a>
<a href="#"><img class="art" src="images/channel_art/netflix-star_trek.jpg" /></a>
<a href="#"><img class="art" src="images/channel_art/netflix-diehard.jpg" /></a>
</div>
For some reason I get a null error when I run
$('.art:nth-child(2)').offset();
while
$('.art:first').offset()
and
$('.art:last').offset()
give values, no problem. Will offset() only return values for the first and last children?
HTML:
<div class="row_titles">
<a href="#"><img class="art" src="images/channel_art/netflix-trainspotting.jpg" /></a>
<a href="#"><img class="art" src="images/channel_art/netflix-ronin.jpg" /></a>
<a href="#"><img class="art" src="images/channel_art/netflix-camelot.jpg" /></a>
<a href="#"><img class="art" src="images/channel_art/netflix-the_fighter.jpg" /></a>
<a href="#"><img class="art" src="images/channel_art/netflix-johnmalkovich.jpg" /></a>
<a href="#"><img class="art" src="images/channel_art/netflix-memento.jpg" /></a>
<a href="#"><img class="art" src="images/channel_art/netflix-star_trek.jpg" /></a>
<a href="#"><img class="art" src="images/channel_art/netflix-diehard.jpg" /></a>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
nth-child
选择器正在选择.art
图像的子 - 由于它们没有任何子项,因此该值为 null。您可以尝试
.row_titles:nth-child(2)
或.art:eq(2)
- 其中任何一个都应该有效。希望这有帮助!
The
nth-child
selector is selecting the children of your.art
images - and since they don't have any children, this is null.You could try
.row_titles:nth-child(2)
, or.art:eq(2)
- either of those should work.Hope this helps!