Last active
December 14, 2015 10:28
-
-
Save Abhinav1217/5071770 to your computer and use it in GitHub Desktop.
# Demo for different methods of selecting the first child element
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset=utf-8 /> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> | |
<title>Demo For first child item</title> | |
<style> | |
.red{color:red;font-size:20px;} | |
</style> | |
</head> | |
<body> | |
<h1>Demo for different methods of selecting the first child element</h1> | |
<ul class="myClass"> | |
<li>1</li> | |
<li>2</li> | |
<li>3</li> | |
<li>4</li> | |
<li>5</li> | |
</ul> | |
<script> | |
// uncomment desired one to test: | |
//$('.myClass > li').eq(0).addClass('red'); | |
//$('.myClass > li:eq(0)').addClass('red'); | |
//$('.myClass > li').first().addClass('red'); | |
//$('.myClass > li:first').addClass('red'); | |
//$('.myClass > li:first-child').addClass('red'); | |
//$('.myClass > li:lt(1)').addClass('red'); | |
//$('.myClass > li').slice(0,1).addClass('red'); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment