:first Selector

first selector

version added: 1.0jQuery(':first')

描述: 选择第一个匹配的元素。

:first伪类相当于:eq(0)。它也可以写为:lt(1)。虽然:first只匹配一个单独的元素,但是:first-child选择器可以匹配超过一个:为每个父级元素匹配第一个子元素。

Example:

Finds the first table row.

<!DOCTYPE html>
<html>
<head>
  <style>

  td { color:blue; font-weight:bold; }
  </style>
  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
  <table>
    <tr><td>Row 1</td></tr>
    <tr><td>Row 2</td></tr>

    <tr><td>Row 3</td></tr>
  </table>
<script>$("tr:first").css("font-style", "italic");</script>

</body>
</html>

Demo:

jQuery 1.6 API 中文版Clove整理、修订