English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

jQuery :only-child Selector

jQuery Selectors

:only-The :only child selector selects each element that is the only child of its parent element.

Syntax:

$(":only-child")

Example

Select each <p> element that is the only child of its parent:

$(document).ready(function(){
  $("p:only-child").css("background", "coral");
});
Test and See‹/›

jQuery Selectors