Find the element before and after a specific element

巧了我就是萌 提交于 2019-12-20 10:30:01

问题


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 :(


回答1:


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

and

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


来源:https://stackoverflow.com/questions/929670/find-the-element-before-and-after-a-specific-element

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!