: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>