First-child selecting first element - Javascript jQuery Selector

Javascript examples for jQuery Selector:first

Description

First-child selecting first element

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <title>First Child Exp</title> 
  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script> 
  <style type="text/css">

.first { background-color: red; }

      </style> 
 </head> //  ww w  .j  a v  a 2 s .com
 <body> 
  <h1>First Child Exp</h1> 
  <div> 
   <div class="category-wrapper"> 
    <a href="#">Test</a> 
   </div> 
  </div> 
  <script type="text/javascript">
$("div.category-wrapper:first-child").addClass("first");

      </script>  
 </body>
</html>

Related Tutorials