Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix nthchild false negative #1757

Merged
merged 2 commits into from Nov 16, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 6 additions & 9 deletions feature-detects/css/nthchild.js
Expand Up @@ -27,15 +27,12 @@ define(['Modernizr', 'testStyles'], function(Modernizr, testStyles) {
// A Javascript loop then tests if the `<div>`s have the expected width
// using the modulus operator.
testStyles('#modernizr div {width:1px} #modernizr div:nth-child(2n) {width:2px;}', function(elem) {
Modernizr.addTest('nthchild', function() {
var elems = elem.getElementsByTagName('div'),
test = true;
var elems = elem.getElementsByTagName('div'),
correctWidths = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this to multiple var's this is an old one but all other tests should use this pattern going forward


for (var i = 0; i < 5; i++) {
test = test && elems[i].offsetWidth === i % 2 + 1;
}

return test;
});
for (var i = 0; i < 5; i++) {
correctWidths = correctWidths && elems[i].offsetWidth === i % 2 + 1;
}
Modernizr.addTest('nthchild', correctWidths);
}, 5);
});