nth child selector

<html>
<head>
<title>jQuery nth-child example</title>
 
<script type="text/javascript" src="jquery.js"></script>
</head>
 
<body>
 
<h1>jQuery nth-child example</h1>
 
<table border=1>
<tr><td>Row #1</td></tr>
<tr><td>Row #2</td></tr>
<tr><td>Row #3</td></tr>
<tr><td>Row #4</td></tr>
<tr><td>Row #5</td></tr>
<tr><td>Row #6</td></tr>
<tr><td>Row #7</td></tr>
<tr><td>Row #8</td></tr>
<tr><td>Row #9</td></tr>
<tr><td>Row #10</td></tr>
</table>
<br/>
 
<button>:nth-child(4)</button>
<button>:nth-child(3n)</button>
<button>:nth-child(even)</button>    
<button>:nth-child(odd)</button>
 
 
<script type="text/javascript">
    $("button").click(function () {
      var str = $(this).text();
      $("tr").css("background", "white");
      $("tr" + str).css("background", "coral");
    });
</script>
 
</body>
</html>

你可能感兴趣的:(nth child selector)