最初のエレメントにアクセスする

書式

$("ele:first")

ele : タグやクラス名等

説明

最初のエレメントにアクセスするには$()で指定するタグ名やクラス名などに:firstを指定します。

サンプルコード [実行]

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Sample</title>
<link rel="stylesheet" href="main.css" type="text/css" media="all">
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript"><!--
$(function (){
$("div:first").html("jQueryサンプル");
});
// --></script>
</head>
<body>
<h1>最初のエレメントにアクセスする</h1>
<div id="result1">--1</div>
<div id="result2">--2</div>
<div id="result3">--3</div>
</body>
</html>