简体   繁体   English

Traverse dom,next,prev

[英]Traverse dom, next, prev

I'm trying to get the next slide element attr href after the active current one. 我正试图在活动当前的一个之后得到下一个幻灯片元素attr href

<ul class="nav">
    <li class="active"><a href="#slide01"></a></li>
    <li><a href="#slide02"></a></li>
    <li><a href="#slide03"></a></li>
    <li><a href="#slide04"></a></li>
</ul>

To get the current one I do 要获得当前的一个

slideActive = $('.nav li.active a').attr('href') which is good it gives #slide02 , however I'm not sure how to get the href of the previous or next li elements. slideActive = $('.nav li.active a').attr('href')这很好,它给#slide02 ,但是我不知道如何获得前一个或下一个li元素的href

Try this: 尝试这个:

1.for selecting the href of the next element 1.选择下一个元素的href

 $('.nav li.active').next('li').find('a').attr('href')

2.for selecting the href of the previous element 2.选择前一个元素的href

$('.nav li.active').prev('li').find('a').attr('href')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM