2010-12-10 37 views
0

我有以下選擇,有沒有什麼辦法可以使這個選擇與$(this)

(選擇.container的第二個div子)

$(".container div:eq(2)").width(); 
+0

`$(this)`是指'$('。container')`? – BoltClock 2010-12-10 05:02:54

+0

是的,這是指$('。container') – ThomasReggi 2010-12-10 05:09:16

回答

1

嘗試

$(".container").each(function(){ 
    $(this).find("div:eq(2)"); // if its not a direct child 
}); 
0

你那裏已經什麼是好的。爲什麼要使用$(this)?你會使用$(this)作爲一個例子,在一個函數:

$(".container div:eq(2)").click(function() { 
    if($(this).width > 100) { 
     ... 
    } 
}); 
0

出了什麼問題:

$(this).find("div:eq(2)").width() 

或:

$("div:eq(2)", this).width() 

順便說一句,從this(其不同於DIV返回第三 DIV後裔的寬度:第n個孩子(2)可以或可以不之前它有兩個兄弟姐妹,:當量()是指在位置在匹配僞數組,不在DOM中)

相關問題