初心者向け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 widthとheight要素の横と縦を設定する

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

no image

疑似クラスと疑似要素

疑似クラスと疑似要素 疑似クラス 疑似クラスとは疑似的に処理をセレクタに追加するものです。 :をつけます。 疑似クラス一覧 :active :any :checked :default :dir() …

no image

jQuery slideUpとslideDownとslideToggle

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

no image

jQuery removeとemptyの違い

removeとemptyの違い removeとemptyの違い removeとemptyの違い。 removeは要素をDOMから削除します。 emptyは要素を子ノードから削除します。 remove …

no image

jQuery:notセレクタの使い方

jQuery jQuery:notセレクタの使い方 jQuery jQuery:notセレクタの使い方 :notセレクタは条件を指定した以外の要素を指定します。 :not(h2) 使用方法はセレクタに …