jQuery - 子セレクタの例のみ

jQuery –子セレクターのみの例

only-child」は、親の唯一の子であるすべての要素を選択するために使用されます。

  1. $(‘:only-child’) – selects all elements that are the only child of their parent.

  2. $(‘li:only-child’) – selects all elements matched by

  3. 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