(jQuery/Selectors)在指定类之后选择元素
问题描述:
我正在尝试使用插件无限滚动
它需要用于下一页链接的选择器.我想如果导航如下,
it requires the selector for the next page link. i suppose that if the navigation is as follows,
<ul>
<li><a href="#" class="active">page 1</a></li>
<li><a href="#" class="next">page 2</a></li>
<li><a href="#">page 3</a></li>
<li><a href="#">page 4</a></li>
<li><a href="#">page 5</a></li>
</ul>
i可以将"a.next"
用作下一页的选择器.但是如果我的页面导航标记如下但没有.next
类
i can use "a.next"
as the selector for the next page. but what happens if my page nav markup is as follows, without the .next
class
<ul>
<li><a href="#" class="active">page 1</a></li>
<li><a href="#">page 2</a></li>
<li><a href="#">page 3</a></li>
<li><a href="#">page 4</a></li>
<li><a href="#">page 5</a></li>
</ul>
假设.active
表示当前页面,我如何选择页面2链接
how can i select the page 2 link assuming .active
signifies the current page
答
要选择.active旁边的节点,可以使用next()函数:
To select the node next to .active, you can use the next() function:
$('.active').next();
但是为什么不添加始终存在的上一个/下一个列表项?
But why not add a prev/next list item that's always there?