<script src="http://dev.ljd.dk/resources/modernizr-2.0.6-c1.js"></script>
<div id="results"></div>
<ul id="credits" style="margin-top:1em; font-size:80%;">
<li>By <a href="http://ljd.dk">Laust Deleuran</a> - <a href="http://twitter.com/laustdeleuran">@laustdeleuran</a></li>
<li>Tested and discussed with <a href="http://twitter.com/emilchristensen">@emilchristensen</a></li>
<li>Core method inspired by <a href="http://jsfiddle.net/westonruter/eAVp2/">Weston Ruter</a></li>
</ul>
JavaScript
// :last-child pseudo selector test.
// By @laustdeleuran and @emilchristensen
// Please see http://reference.sitepoint.com/css/pseudoclass-lastchild for weird :last-child behaviour in FireFox below 2.0 and Safari below 2.0.
// Original Modernizr test here: http://jsfiddle.net/laustdeleuran/3rEVe/ and Pure JS here: http://jsfiddle.net/laustdeleuran/hvZ3J/
Modernizr.addTest('lastchild', function () {
return Modernizr.testStyles("#modernizr div {width:100px} #modernizr :last-child{width:200px;display:block}", function(elem) {
return elem.lastChild.offsetWidth > elem.firstChild.offsetWidth;
}, 1);
});
// Output result
document.getElementById("results").innerHTML = Modernizr.lastchild ? "Yes! I support the :last-child pseudo selector." : "No - so sorry, but I have no clue what the :last-child pseudo selector is.";
document.getElementById("results").style.color = Modernizr.lastchild ? "green" : "red";
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.