Alternative for nth-child for older IE browsers

前端 未结 4 998
野趣味
野趣味 2020-12-06 08:36

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

Javascript (non-jquery) would suffice as well.

EDIT: Giv

相关标签:
4条回答
  • 2020-12-06 08:42

    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
    
    0 讨论(0)
  • 2020-12-06 08:47

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

    0 讨论(0)
  • 2020-12-06 08:49

    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.

    0 讨论(0)
  • 2020-12-06 08:52

    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.

    0 讨论(0)
提交回复
热议问题