jQuery | :parent Selector
The :parent selector in jQuery is used to select all elements that are the parent of another element, including text nodes.
Syntax:
$(":parent")
Example:
<!DOCTYPE html> < html > < head > < title > jQuery :parent() Selector </ title > < script src = </ script > < script > $(document).ready(function() { $("li:parent").css( "background-color", "green"); }); </ script > </ head > < body > < center > < h1 id = "geeks1" > GeeksForGeeks</ h1 > < h2 id = "geeks2" > jQuery :parent() Selector </ h2 > < div > < li >Geek1</ li > < li ></ li > < li >Geek3</ li > < li >Geek4</ li > < li ></ li > < li >Geek6</ li > </ div > </ center > </ body > </ html > |
Output:
Supported Browsers: The browser supported by jQuery :parent Selector are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari