Open In App

jQuery has() Method

Improve
Improve
Like Article
Like
Save
Share
Report

The has() is an inbuilt method in jQuery which is used to find all the elements inside the specified list of elements. 

Syntax: 

$(selector).has(element)

Parameter: It accepts a parameter expression or an element to match elements against them. 

Return Value: It returns all elements that match the specified selector having one or more elements inside them. 

jQuery code to show the working of has() method: 

Example 1:  

HTML




<!DOCTYPE html>
<html>
 
<head>
    <script src=
    </script>
    <!-- jQuery code to show the working of this method -->
    <script>
        $(document).ready(function () {
            $("p").has("span").css(
                "background-color", "lightgreen", "bold");
        });
    </script>
    <style>
        body {
            width: 50%;
            height: 100px;
            border: 2px solid green;
            padding: 15px;
            font-size: 19px;
        }
    </style>
</head>
 
<body>
    <p>
        Geeks
        <span>for</span>
        Geeks !
    </p>
 
    <p>
        I am a
        <span>content</span>
        writer.
    </p>
 
    <p>
        This is a normal paragraph .
    </p>
</body>
 
</html>


Output: 
All the “p” elements containing the “span” elements get highlighted. 



Last Updated : 07 Jul, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads