2011-05-24 42 views
1

嗨我試圖使用:最後一個孩子在IE8中沒有結果。 的什麼,我試圖做一個例子是jQuery:最後一個孩子在IE8中不工作

jQuery(".menu-item:last-child").addClass("clear-right"); 

這無處不在正常工作對我,但IE和建議?

+4

你能張貼代碼和HTML你使用?那麼也許我們可以幫助你更好。 – 2011-05-24 17:35:01

+2

我們真的需要在這裏看到這個html – mcgrailm 2011-05-24 17:38:33

+3

是否有可能選擇器*工作,但CSS不是? – karim79 2011-05-24 17:45:52

回答

-1

試試這個:

jQuery(".menu-item").children().last().addClass("clear-right"); 
       // get children->last child 

DEMO

+4

-1:它們不是一回事。 :最後孩子選擇作爲其父項的最後一個孩子的所有.menu項目。 jQuery.last()只是獲取jQuery對象中的最後一項。 – Andre 2011-05-24 17:40:09

+0

@Andre,我更新了我的答案 – Neal 2011-05-24 17:42:49

+0

仍然不是一回事。用:最後一個孩子,元素本身是它的父親的最後一個孩子,你得到元素的孩子。這裏:http://jsfiddle.net/PBAas/4/ – Andre 2011-05-24 18:06:06

1

我假設菜單項ul li元素。

$(".menu-item li:last-child").addClass("clear-right"); 

demo

5

jQuery代碼效果很好,但要注意,那IE8扔掉含有CSS3等(多)選擇之間:last-child選擇整個CSS聲明。例如:

.menu-item:last-child, menu-item.clear-right { 
    clear: right; 
} 

在IE8不工作,但以下工作無處不在:

.menu-item:last-child { 
    clear: right; 
} 
menu-item.clear-right { 
    clear: right; 
} 
相關問題