Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
nth-last-child
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
li:nth-last-child(3) { background-color: red; }
</style>
</head>
<body>
<div id="container">
<button>add</button>
<ul>
<li>Foo</li>
<li>Foo</li>
</ul>
<div id="log"></div>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script>
$(function($) {
$('button').on('click', function() {
$('ul').append('<li>' + new Date() + '</li>');
$('#log').text($('li:nth-last-child(3)').text());
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment