
- jQuery - Home
- jQuery - Roadmap
- jQuery - Overview
- jQuery - Basics
- jQuery - Syntax
- jQuery - Selectors
- jQuery - Events
- jQuery - Attributes
- jQuery - AJAX
- jQuery CSS Manipulation
- jQuery - CSS Classes
- jQuery - Dimensions
- jQuery - CSS Properties
- jQuery Traversing
- jQuery - Traversing
- jQuery - Traversing Ancestors
- jQuery - Traversing Descendants
- jQuery References
- jQuery - Selectors
- jQuery - Events
- jQuery - Effects
- jQuery - HTML/CSS
- jQuery - Traversing
- jQuery - Miscellaneous
- jQuery - Properties
- jQuery - Utilities
- jQuery Plugins
- jQuery - Plugins
- jQuery - PagePiling.js
- jQuery - Flickerplate.js
- jQuery - Multiscroll.js
- jQuery - Slidebar.js
- jQuery - Rowgrid.js
- jQuery - Alertify.js
- jQuery - Progressbar.js
- jQuery - Slideshow.js
- jQuery - Drawsvg.js
- jQuery - Tagsort.js
- jQuery - LogosDistort.js
- jQuery - Filer.js
- jQuery - Whatsnearby.js
- jQuery - Checkout.js
- jQuery - Blockrain.js
- jQuery - Producttour.js
- jQuery - Megadropdown.js
- jQuery - Weather.js
jQuery :only-of-type Selector
The :only-of-type selector in jQuery is used to select elements that are the only child of their type within their parent.
Syntax
Following is the syntax of jQuery :only-of-type Selector −
$(":only-of-type")
Parameters
This selector targets elements that are the only child of their type within their parent.
Example
In the following example, we are using the jQuery :only-of-type Selector to select each <p> element that is the only <p> element of its parent (<div>)−
<html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("p:only-of-type").css("background-color", "yellow"); }); </script> </head> <body> <div style="border: 1px solid black;"> <p>This paragraph is the only one of its type within the parent div.</p> <p>This paragraph is another paragraph within the parent div.</p> </div><br> <div style="border: 1px solid black;"> <p>This paragraph is the only one of its type within the parent div.</p> </div><br> <div style="border: 1px solid black;"> <p>This paragraph is the only one of its type within the parent div.</p> </div> </body> </html>
After executing the above program, it applies yellow background color to the only paragraph of its type within the div.
jquery_ref_selectors.htm
Advertisements