eq: eq(index | -index)
index:是一个整数从0开始,获取相应的元素。
-index: 是从最后一个元素开始数(倒着选取),从一开始。
eg:
<p>
This is just a test.
</p>
<p>
So is this
</p>
$("p").eq(1)
$("p").eq(-2)
结果:[So is this]
结果:[This is just a test.]
first(): 获取匹配的第一个元素
eg:
<li>
aaaaa
</li>
<li>
bbbbb
</li>
<li>
ccccc
</li>
$("li").first() 结果:[aaaaa]
last(): 获取匹配的最后一个元素
$("li").last() 结果:[ccccc]
hasClass(class) 检查当前的元素是否含有某个特定的类(class),如果有则返回true。
eg: 给包含某个类的元素进行一个动画
$("div").click(function(){
if($(this).hasClass("prop"){
$(this)
.animate({ left: 10 })
.animate({ left: -10})
.animate({ left: 10})
.animate({ left: 0})
})
});
animate() // 该方法通过CSS样式将元素从一个状态改变为另一个状态。CSS属性值是逐渐改变的,这样就可以创建动画效果。