मैं सिर्फ पता लगाने के लिए एक समारोह लिखा है: के लिए n वें-बाल सहायता आप
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;
}
उपयोग:
isNthChildSupported() ? console.log('yes nth child is supported') : console.log('no nth child is NOT supported');
आप इस क्रिया में यहाँ http://jsbin.com/epuxus/15
भी काम करता है देख सकते हैं jQuery :nth-child
और CSS :nth-child
के बीच एक अंतर है।
jQuery :nth-child
किसी भी ब्राउज़र jQuery का समर्थन करता है लेकिन सीएसएस में समर्थित है IE9, क्रोम, सफारी और Firefox
ईमानदारी से कहूं तो यह मान लेना कि एक ब्राउज़र या तो दोनों 'समर्थन करता है, बहुत ही उचित है: n वें वाले बच्चे()' और ': अंतिम child', या किसी भी समर्थन नहीं करता। – BoltClock
इस प्लगइन को आजमाएं .. http://selectivizr.com/
केवल सीएसएस फ़ाइल के अंतर्गत/उसके बाद डालें! –