acabo de escribieron una función para detectar el: apoyo nth-child para usted
function isNthChildSupported(){
var result = false,
test = document.createElement('ul'),
style = document.createElement('style');
test.setAttribute('id', 'nth-child-test');
style.setAttribute('type', 'text/css');
style.setAttribute('rel', 'stylesheet');
style.setAttribute('id', 'nth-child-test-style');
style.innerHTML = "#nth-child-test li:nth-child(even){height:10px;}";
for(var i=0; i<3; i++){
test.appendChild(document.createElement('li'));
}
document.body.appendChild(test);
document.head.appendChild(style);
if(document.getElementById('nth-child-test').getElementsByTagName('li')[1].offsetHeight == 10) {result = true;}
document.body.removeChild(document.getElementById('nth-child-test'));
document.head.removeChild(document.getElementById('nth-child-test-style'));
return result;
}
Uso:
isNthChildSupported() ? console.log('yes nth child is supported') : console.log('no nth child is NOT supported');
se puede ver que esto funciona en acción aquí http://jsbin.com/epuxus/15
también Hay una diferencia entre jQuery :nth-child
y CSS :nth-child
.
jQuery :nth-child
se soportado en cualquier navegador compatible con jQuery, pero CSS :nth-child
is supported en IE9, Chrome, Safari y Firefox
para ser honesto, es muy razonable suponer que un navegador sea compatible con ': nth-child()' y ': último child', o si no admite tampoco. – BoltClock
Pruebe este complemento ... http://selectivizr.com/
inserte debajo/después del archivo css solamente! –