jQueryのchildren()の例

jQuery children()の例

jQueryでは、children()を使用して、一致した要素の子を検索します。これはtravels a single level downのみです。

たとえば、深さ3レベルのdiv要素には、クラス名「child」および「orphan」が含まれます。

A1-1
A1-2
A1-3
A1-4
A2-1
A2-2
A3-1
A3-2

1. $(‘.A1’).children()

$('.A1').children().css('background','red');

A1」のクラス名とすべてのA1single level child」を含む要素に一致します。

P.S The A2 and A3 child will be ignore.

2. $(‘.A1’).children(‘.child’)

$('.A1').children('.child').css('background','red');

A1」のクラス名を含む要素を照合し、「child」のクラス名を含む「A1」の子を検索します。 この例では、all the A1 “single level child” except child with a class name of “orphan” will be selectです。

jQuery children()の例












jQuery children() example

A1-1
A1-2
A1-3
A1-4
A2-1
A2-2
A3-1
A3-2