Created
August 6, 2013 09:53
-
-
Save willhalling/6163249 to your computer and use it in GitHub Desktop.
Identify first item.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> | |
<title>Identify first item</title> | |
<script type="text/javascript"> | |
$(function() { | |
// add .first class to identify first div | |
$('#wrap').children().each(function(i,obj){ | |
$this = $(this); // cache $(this) | |
if (i <= 0) { | |
$this.children().addClass('first'); | |
$this.css('background','red'); | |
} | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<div id="wrap"> | |
<div id="div-1">div 1</div> | |
<div id="div-2">div 2</div> | |
<div id="div-3">div 3</div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment