prev():指定した要素の前の兄弟要素の取得(prev)
指定した要素の前の兄弟要素の取得(prev)の書式
要素名.prev()
指定した要素の前の兄弟要素の取得(prev)する場合は、要素名.prev()を記述します。
指定した要素の前の兄弟要素の取得(prev)のサンプルコード)
サンプルではprevメソッドで指定した要素の前の兄弟要素の取得をして以下の事をしてます。
1.cssメソッドを使って、colorを変更。
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
<!--
body {background-color: #ffffff;}
-->
</style>
<script src="../../js/jquery-1.12.2.min.js"></script>
<script>
$(function(){
$("strong#idTest").prev().css("color", "#ff0000");
});
</script>
</head>
<body>
<div>テスト1</div>
<ol>
<li>インデックス番号:0</li>
<li>インデックス番号:1</li>
<li>インデックス番号:2
<p>prev<font style="font-size:20px;">FONT</font></p>
<p>prev<font style="font-size:20px;">FONT</font></p>
<strong id = "idTest">test</strong>
<p>prev<font style="font-size:20px;">FONT</font></p>
<p>prev<font style="font-size:20px;">FONT</font></p>
</li>
<li>インデックス番号:3</li>
<li>インデックス番号:4</li>
</ol>
<div>テスト2</div>
</body>
</html>
