Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<meta charset=utf-8 />
<title>roXon</title>
  
<style>
  .red{color:red;font-size:20px;}
  
</style>
</head>
<body>
  <ul>
    <li>1</li>
    <li>2
        <ul>
            <li>2.1</li>
            <li>2.2</li>
        </ul>
    </li>
    <li>3</li>
  </ul>
    
  
  
</body>
</html>
 
// uncomment desired one to test the differences:
// $('li').eq(0).addClass('red');
// $('li:eq(0)').addClass('red');
// $('li').first().addClass('red');
// $('li:first').addClass('red');
// $('li:first-child').addClass('red');  // note this one
// $('li:lt(1)').addClass('red');
// $('li:nth-child(1)').addClass('red'); // note this one
// $('li').slice(0,1).addClass('red');
// $('li')[0].className = 'red';
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers