Alternative for nth-child for older IE browsers

╄→гoц情女王★ 提交于 2019-11-26 21:24:32

问题


Is there an alternative for targeting elements using nth-child() for older IE browsers?

Javascript (non-jquery) would suffice as well.

EDIT: Given additional libraries cannot be added to the page.


回答1:


You can use jQuery's :nth-child() selector;

$("li:nth-child(even)") // target even li's
$("li:nth-child(odd)") // target odd li's
$("li:nth-child(5n)") // target the fifth li



回答2:


it sucks a little, but you can

ul > li {} /* first-child, overwritten by below */
ul > li + li {} /* second-child, overwritten by below, etc */
ul > li + li + li {}
ul > li + li + li + li {}

Repeat as necessary.




回答3:


There is Selectivizr: http://selectivizr.com/

:nth-child is supported in every javascript framework that works with it, including jQuery.

The big advantage with using this is that it reads directly from your CSS files rather than having to write additional javascript (it's unobtrusive). You can simply use the advanced selectors as normal.




回答4:


You can use the IE9.js polyfill: http://ie7-js.googlecode.com/svn/test/index.html.



来源:https://stackoverflow.com/questions/8733475/alternative-for-nth-child-for-older-ie-browsers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!