初心者向けjQuery入門

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

未分類

jQuery prevALLとnextALL前と後の兄弟要素を全て取得する

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

jQuery prevALLとnextALL前と後の兄弟要素を全て取得する

jQuery prevALL前の兄弟要素を全て取得する

prevALLメソッドは指定した前の兄弟要素を全て取得します。

サンプル

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

サンプル

<html>

<head>

<script src=”jquery-3.2.1.js”></script>
<script>$(function(){
$(“.botton”).click(function(){

$(“.three”).prevAll().css(“color”,”red”)
});

});</script>

<title>
</title>

</head>

<body>

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

<div>

<ul><li>1</li>

<li >2</li>

<li class=”three”>3</li>

<li>4</li>

<li>5</li></ul>

</div>

</body>

</html>

threeクラスの前の兄弟を取得して赤にしてます。

この場合1と2が赤になってます。

 

jQuery nextALL後の兄弟要素を全て取得する

nextALLメソッドは指定した後の兄弟要素を全て取得します。

サンプル

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

サンプル

<html>

<head>

<script src=”jquery-3.2.1.js”></script>
<script>$(function(){
$(“.botton”).click(function(){

$(“.three”).nextAll().css(“color”,”red”)
});

});</script>

<title>
</title>

</head>

<body>

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

<div>

<ul><li>1</li>

<li >2</li>

<li class=”three”>3</li>

<li>4</li>

<li>5</li></ul>

</div>

</body>

</html>

実行結果は

threeクラスの後ろの兄弟を取得して赤にしてます。

この場合3と4が赤になってます。

セレクタで指定したクラスは赤にならないので境界を間違えないよに注意しましょう。

 

スポンサードリンク




スポンサードリンク




-未分類
-

執筆者:


comment

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

関連記事

no image

jQuery mouseenterとmouseleaveマウスイベントの方法

jQuery mouseenterとmouseleaveマウスイベントの方法 jQuery mouseenterマウスを乗せた時のイベント方法 mouseenterはマウスを乗せた時に発生するイベント …

no image

jQuery addclassクラスを追加する方法

jQuery addclassクラスを追加する方法 jQuery addclassクラスを追加する方法 addclassクラスは要素にクラスを設定できます。 どういうことかというこクラスのタブにhtm …

no image

jQuery animate要素をアニメーションさせる

jQuery animate要素をアニメーションさせる jQuery animate要素をアニメーションさせる animateの英語の意味は 生命を吹き込む,活気づける、活発にする、励ます、動画にする …

no image

jQuery widthとheight要素の横と縦を設定する

jQuery widthとheight要素の横と縦を設定する jQuery width 要素のサイズの横幅を設定するにはwidthメソッドを使用します。 $(“セレクタ”).w …

no image

jQuery 複数のcssのプロパティの設定の方法

jQuery 複数のcssのプロパティの設定の方法 jQuery 複数のcssのプロパティの設定の方法 jQueryでcssを複数設定の方法。 メソッドチェーンで書くとこんな感じになります。 $(&# …