jQuery - Descendantセレクタの例

jQuery –子孫セレクターの例

jQuery descender selector (X Y)は、「X」要素の子、孫、ひ孫、ひ孫..(任意のレベルの深さ)である「Y」に一致するすべての要素を選択するために使用されます。

例えば、

  • $(‘#container div’) –コンテナのIDを持つ要素の子孫である

    に一致するすべての要素を選択します。

  • $(‘form input’)

    に一致する要素の子孫であるに一致するすべての要素を選択します。

jQueryの例

この例では、jQueryの子孫セレクターを使用して、「赤い枠線」を要素の子孫であるすべてのフィールドに追加しました。



jQuery descendant selector example



 







jQuery child selector example

I'm form siblings #1 - DIV

I'm form siblings #2 - P

I'm form siblings #3 - DIV

I'm form siblings #4 - P