jQuery –子セレクターのみの例
「only-child」は、親の唯一の子であるすべての要素を選択するために使用されます。
例
-
$(‘:only-child’) – selects all elements that are the only child of their parent.
-
$(‘li:only-child’) – selects all elements matched by
- that are the only child of their parent.
jQueryの例
この例では、ボタンがクリックされると、<li>DEF #1</li>のみが一致し、その背景色が動的に変更されます。これは、ボタンが親の唯一の子であるためです。
jQuery only child example jQuery only child example
- ABC #1
- ABC #2
- ABC #3
- ABC #4
- ABC #5
- DEF #1
- GHI #1
- GHI #2