Jam*_*mes 29 html jquery dom css-selectors jquery-selectors
你怎么知道当前元素是不是第一个孩子?
它应该适用于$(this)
,例如:
$("li").click(function(e) {
if (/* $(this) is not the first-child */)
{
/* do something */
}
});
Run Code Online (Sandbox Code Playgroud)
sli*_*kts 57
你可以这样做只是为了测试一个元素,如果它是第一个孩子:$(this).is(':first-child')
.其他选择器:last-child
也会起作用.
use*_*716 30
你可以简单地询问它的.index()
位置(相对于它的兄弟姐妹).
$(this).index(); // returns a zero based index position
Run Code Online (Sandbox Code Playgroud)
Ste*_*ler 10
对于所有li
的在#thing
不在第一个孩子:
$('#thing li:not(:first-child)')
Run Code Online (Sandbox Code Playgroud)
见http://api.jquery.com/not-selector/
另外,您可以检查是否$(this).prev().length
已定义,例如:
if (!$(this).prev().length){ //This means $(this is the first child
//do stuff
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
39593 次 |
最近记录: |