IE8 and jQuery selectors

前端 未结 2 1929
庸人自扰
庸人自扰 2020-12-16 01:12

Today it came to my attention that a combination of jQuery selectors and the addClass() function does not work properly on IE8.

For example, when I want to ensure th

2条回答
  •  不思量自难忘°
    2020-12-16 01:17

    The selector works correctly on the jQuery side...but IE8 discards the style rule entirely (in compliance with the specification) because it doesn't recognize nth-child:

    tr:nth-child(odd) td, tr.odd td {
      background-color: #86B486;
    }
    

    If you split it, it'll work correctly:

    tr:nth-child(odd) td {
      background-color: #86B486;
    }
    tr.odd td {
      background-color: #86B486;
    }
    

    Here's the original version (a single rule IE8 removes) and here's a fixed sample, with the rule split.


    For completeness sake, reversing the rule like this doesn't help:

    tr.odd td, tr:nth-child(odd) td {
      background-color: #86B486;
    }
    

提交回复
热议问题