本文介绍了在某个元素之后查找课程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个具有相同类month
的元素列表.其中一些可能也具有类cal
,并且列表中只有一个元素具有类today
.
I have a list of elements with the same class month
. Some of them might have the class cal
as well, and only one element of the list has the class today
.
我想搜索类cal
的第一个元素,但仅在找到元素today
之后
I'd like to search for the first element with the class cal
, but only after the element today
is found
例如,如果我有以下列表:
So for example, if I have the following list:
<ul id="eventCal">
<li class="month"></li>
<li class="month cal">Not show because it's before TODAY</li>
<li class="month"></li>
<li class="month"></li>
<li class="month"></li>
<li class="month today">Today</li>
<li class="month"></li>
<li class="month cal">To show as it's the first CAL after the TODAY</li>
<li class="month cal">Not show because is not the first CAL</li>
<li class="month"></li>
</ul>
推荐答案
您可以使用:first
来获取今天的第一个li,然后将nextAll
与:first
一起使用来获取今天之后的第一个cal
You can make use of :first
to get the first today li and then use nextAll
with :first
to get first cal after today
$(function(){
var text = $('#eventCal li.today:first').nextAll('li.cal:first').text();
console.log(text);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<ul id="eventCal">
<li class="month"></li>
<li class="month cal">Not show because it's before TODAY</li>
<li class="month"></li>
<li class="month"></li>
<li class="month"></li>
<li class="month today">Today</li>
<li class="month"></li>
<li class="month cal">To show as it's the first CAL after the TODAY</li>
<li class="month cal">Not show because is not the first CAL</li>
<li class="month"></li>
</ul>
这篇关于在某个元素之后查找课程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!