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

  • by using jQuery :parent Selector.
  • HTML `

    jQuery :parent() Selector
    <script>
        $(document).ready(function () {
            $("li:parent").css(
                "background-color", "green");
        });
    </script>

    GeeksForGeeks

    jQuery :parent() Selector

  • Geek1
  • Geek3
  • Geek4
  • Geek6
  • `

    Output:

    Example 2: In this example, we will add a border to the parent elements of

  • with the help of click function.
  • HTML `

    jQuery :parent() Selector
    <script>
        $(document).ready(function () {
            $("button").click(function () {
                $("li:parent").css(
                    "border", "2px solid red");
            });
        });
    </script>

    GeeksForGeeks

    jQuery :parent() Selector

  • Geek1
  • Geek3
  • Geek4
  • Geek6

  • Add Border

    `

    Output: