first-child Selector- jQuery


$( “:first-child” ) – selector is used to select the first child of its parent.


Syntax : first-child Selector using jQuery

first-child Selector- jQuery Example

<!DOCTYPE html>
<html>
<head>
<title>first-child Selector- jQuery Example</title>
 <script type="text/javascript" src="http://code.jquery.com/jquery-2.1.4.min.js">
 </script>
<script type="text/javascript">
         $(document).ready(function(){
         $("#demo").click(function(){
          $("ol li:first").css("border","4px solid red");
          $("ol li:first").css("color","blue");
          $("ol li:first").css("font-size","26px");
          });
          });
</script> 
  
</head>	
<body>
<a href="javascript:void(0)" id="demo"> 
Click Me
</a>
<ol>
  <li> First Item </li>
  <li> Second Item </li>
  <li> Third Item </li>
</ol>
</body>
</html>             

Try it »


User Ans/Comments

📖 Read More


Advertisements