Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added 'first-child' pseudo-selector test. #717

Closed
wants to merge 1 commit into from

2 participants

@bmcustodio

This is pretty much just an small rewrite of the 'css-lastchild.js' feature test already present on Modernizr to allow for the detection of browser support for the :first-child pseudo-selector. I am pretty sure that every browser that supports :last-child also supports :first-child (and vice-versa), and as such including this may sound a bit redundant, but if I am using :first-child anywhere I'd rather write

.firstchild {
    /* (...) */
}
.no-firstchild {
    /* (...) */
}

than .lastchild and .no-lastchild.

Build Status

feature-detects/css-firstchild.js
@@ -0,0 +1,7 @@
+// 'first-child' pseudo-selector test.
+
+Modernizr.addTest('firstchild', function(){
@sindresorhus Collaborator

function() {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
feature-detects/css-firstchild.js
@@ -0,0 +1,7 @@
+// 'first-child' pseudo-selector test.
+
+Modernizr.addTest('firstchild', function(){
+ return Modernizr.testStyles("#modernizr div {width:100px} #modernizr :first-child {width:200px;display:block}", function (elem) {
@sindresorhus Collaborator

function(elem) {

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

@sindresorhus: Had passed really unnoticed. :-) Fixed. Thank you very much.

@bmcustodio

@KuraFire, @paulirish: Any chances this might get merged?

@bmcustodio bmcustodio closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 26, 2013
  1. @bmcustodio
This page is out of date. Refresh to see the latest.
Showing with 7 additions and 0 deletions.
  1. +7 −0 feature-detects/css-firstchild.js
View
7 feature-detects/css-firstchild.js
@@ -0,0 +1,7 @@
+// 'first-child' pseudo-selector test.
+
+Modernizr.addTest('firstchild', function() {
+ return Modernizr.testStyles("#modernizr div {width:100px} #modernizr :first-child {width:200px;display:block}", function(elem) {
+ return elem.firstChild.offsetWidth > elem.lastChild.offsetWidth;
+ }, 2);
+});
Something went wrong with that request. Please try again.