jQuery :parent Selector (original) (raw)
Last Updated : 11 Jul, 2025
The jQuery :parent selector is used to select all elements that are the parent of another element, including text nodes.
Syntax:
$(":parent")
Example 1: In this example, we will select all the parent elements of the
HTML `
jQuery :parent() Selector<script>
$(document).ready(function () {
$("li:parent").css(
"background-color", "green");
});
</script>
GeeksForGeeks
jQuery :parent() Selector
`
Output:
Example 2: In this example, we will add a border to the parent elements of
HTML `
jQuery :parent() Selector<script>
$(document).ready(function () {
$("button").click(function () {
$("li:parent").css(
"border", "2px solid red");
});
});
</script>
GeeksForGeeks
jQuery :parent() Selector
Add Border
`
Output:
