Skip to content

Instantly share code, notes, and snippets.

@og-shawn-crigger
Forked from meyertee/css-nthchildn.js
Created April 4, 2012 18:15
Show Gist options
  • Save og-shawn-crigger/2304388 to your computer and use it in GitHub Desktop.
Save og-shawn-crigger/2304388 to your computer and use it in GitHub Desktop.
Modernizr Test 'nthchildn'
// Test for nth-child(...n) support
Modernizr.testStyles(" #modernizr div:nth-child(3n){width:10px;} ", function(elem, rule){
var bool = false, divs = elem.getElementsByTagName("div");
if (divs.length == 7){
var test = window.getComputedStyle ? function(i){
return getComputedStyle(divs[i], null)["width"] == "10px";
} : function(i){
return divs[i].currentStyle["width"] == "10px";
};
bool = !test(0) && !test(1) && test(2) && !test(3) && !test(4) && test(5) && !test(6);
}
Modernizr.addTest("nthchildn", bool);
}, 7);
@og-shawn-crigger
Copy link
Author

Polyfill for CSS property nthchild for IE7-8 uses Modernizr

USAGE

if (!Modernizr.nthchildn) {  
  $('.span4:even').addClass('margless');
}

If not support for nthchild then add class to elements

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment