jQuery 查找特定元素前后的元素

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/929670/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 10:08:51  来源:igfitidea点击:

Find the element before and after a specific element

jquerytraversal

提问by rebellion

I have a list with links I use with tabs. It looks like this:

我有一个带有标签的链接列表。它看起来像这样:

<ul>
    <li><a href="#">First tab</a></li>
    <li><a href="#">Second tab</a></li>
    <li class="active"><a href="#">Active tab</a></li>
    <li><a href="#">Fourth tab</a></li>
    <li><a href="#">Fifth tab</a></li>
</ul>

How can I find the list element before and after the active tab? (In this case, the second and fourth tab).

如何在活动选项卡之前和之后找到列表元素?(在本例中为第二个和第四个选项卡)。

Tried using find, with no success :(

尝试使用查找,但没有成功:(

回答by cletus

$("li.active").next();

and

$("li.active").prev();