初心者向けjQuery入門

初心者向けjQuery入門講座です

未分類

jQuery prevとnext前と後の要素取得する

投稿日:2017年8月20日 更新日:

jQuery prevとnext前と後の要素取得する

jQuery prev前の要素取得する

prevは英語の略語で

previous(以前の)

等です。

prevは指定した要素の前の要素を取得します。

サンプル

$(“セレクタ”).prev().メソッド()

 

サンプル

<html>

<head>

<script src=”jquery-3.2.1.js”></script>
<script>

$(function(){
$(“.botton”).click(function(){

$(“.two”).prev().css(“color”,”red”)
});

});</script>

<title>
</title>

</head>

<body>

<input type=”button” value=”botton” class= “botton” >

<div>

<ul>

<li>1</li>

<li class=”two”>2</li>

<li>3</li>

</ul>

</div>

</body>

</html>

実行結果は

1の色が赤になります。

jQuery next後の要素取得する

nextは英語で次です。

次ということは指定した要素の後ろの要素ですね。

サンプル

$(“セレクタ”).next().メソッド

サンプル

<html>

<head>

<script src=”jquery-3.2.1.js”></script>
<script>

$(function(){
$(“.botton”).click(function(){

$(“.two”).prev().css(“color”,”red”)
});

});</script>

<title>
</title>

</head>

<body>

<input type=”button” value=”botton” class= “botton” >

<div>

<ul>

<li>1</li>

<li class=”two”>2</li>

<li>3</li>

</ul>

</div>

</body>

</html>

実行結果は

3が赤になります。

 

スポンサードリンク




スポンサードリンク




-未分類
-

執筆者:


comment

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

関連記事

no image

jQuery firstとlast最初と最後の要素を取得する

jQuery firstとlast最初と最後の要素を取得する jQuery first最初の要素を取得する firstメソッドは最初の要素を取得します。 サンプル $(“セレクタ&#822 …

no image

jQuery チルダ~の間接セレクタと兄弟セレクタ

jQuery チルダ~の間接セレクタと兄弟セレクタ jQuery チルダ~の間接セレクタと兄弟セレクタ 間接セレクタはチルダを使用します。 兄弟とは親が同じだということですね。 動作は指定した兄弟の以 …

no image

jQuery removeClassクラスを削除する方法

jQuery removeClassクラスを削除する方法 jQuery removeClassクラスを削除する方法 htmlで設定したクラスを削除します。 cssで設定したクラスでも削除はできます。 …

no image

jQuery メソッドチェーンとメソッドの種類の使い方

jQuery メソッドチェーンとメソッドの種類の使い方 jQuery メソッドの種類の使い方 メソッドは何らかの処理を実行するためにあります。 $(“セレクタ”).メソッド(パ …

no image

jQuery slideUpとslideDownとslideToggle

jQuery slideUpとslideDownとslideToggle jQuery slideUp slideUpはスライドをアップします。 要素が上に上がっていき非表示になります。 サンプル $ …