jQuery :onlyoftype Selector (original) (raw)
jQuery :only-of-type Selector
Last Updated : 11 Jul, 2025
The ****:only-of-type Selector** is an inbuilt selector in **jQuery, used to select all the elements that are the only child of their parent.
**Syntax:
$("parent_name : only-of-type")
**Example 1: In this example, we are using only-of-type selectors.
HTML `
Geek1 of first div.
Geek2 of first div.
The only Geek of second div.
The only Geek of third div.
`
**Output:
In the above example, all the only child element( here p tags ) of their parent( here div tags ) are formatted into green color i.e, "The only Geek of the second div." and "The only Geek of the third div.".
**Example 2:
html `
Division as a parent
Geek1 of div.
Geek2 of div.
ID as a parent.
The only Geek of id.
Class as a parent.
The only Geek of class.
Body as a parent.
The only Geek of body.
`
**Output:
In the above example, all the only child element( here p tags ) of their respective parent are formatted into green color i.e, "The only Geek of id.", "The only Geek of class." and "The only Geek of the body." as every paragraph tag is considered the different child for each parent.