类的最后一个要素 [英] Last element of Class
本文介绍了类的最后一个要素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检查具有某个类的元素是否是该类的最后一个?
How can I check if a element with a certain class is the last of that class?
<div class="foo"></div>
<div class="foo"></div>
<div class="foo"></div>
<div class="foo"></div>
<div class="foo"></div>
<div class="foo"></div>
<div class="foo"></div>
<div class="foo"></div> // I want to check if this is the last element of this class
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
推荐答案
由于我不确定您如何识别此变量,因此可以说$foo
是该特定元素的jQuery对象.
As I'm not sure how you are identifying this variable, lets say $foo
is a jQuery object for that particular element.
您可以这样做:
if (!$foo.next(".foo").length){
//its the last foo
}
实时演示: http://jsfiddle.net/2W6eT/
这篇关于类的最后一个要素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文