Style LI by :first-child and :last-child - Javascript jQuery Selector

Javascript examples for jQuery Selector:first-child

Description

Style LI by :first-child and :last-child

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.6.4.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){/*from   ww  w. j a v a 2s .com*/
$("ul li:first-child").css("background","red");
$("ul li:last-child").css("background","red");
    });

      </script> 
 </head> 
 <body> 
  <ul> 
   <li>Hello</li> 
   <li>world</li> 
   <li>, i am</li> 
   <li>an alien!</li> 
  </ul>  
 </body>
</html>

Related Tutorials