1.

.find() 

編集

.find() 

・jQueryオブジェクトで指定した要素のうち、指定した条件に合致する子孫要素を選択する。

 

■.find( selector )

戻り値:jQuery

引数 説明
selector 検索対象をセレクタで指定

 

 

■.find( jQuery object ) 

戻り値:jQuery

引数 説明
jQuery object 検索対象をjQueryオブジェクトで指定

 

 

■.find( element )

戻り値:jQuery

引数 説明
element 検索対象をDOM要素で指定

 

 

使用例)

HTML

"<!DOCTYPE html>

<html>

<head>

    <meta charset="utf-8">

        <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>

        <script>

            $(function(){

                $("p").find("span").css("color","red");

            });

        </script>

</head>

<body>

    <p>黒<span>赤</span><span>赤</span></p>

</body>

</html>"

pタグで要素を絞り、findメソッドでspanタグを指定し、さらに要素を絞る。

pタグ内spanタグ内にのみ処理が適応される。

 

 

 


 

 

編集
Post Share
子ページ

子ページはありません

同階層のページ
  1. .find() 
  2. .children()
  3. .eq()