jQuery | has() with Examples
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.
Code #1:
<html> <head> <script </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 paragrap .</p> </body> </html> |
Output:
All the “p” elements containing the “span” elements get highlighted.

Recommended Posts:
- jQuery | val() with Examples
- jQuery | first() with Examples
- jQuery | last() with Examples
- jQuery | on() with Examples
- jQuery | after() with Examples
- jQuery | eq() with Examples
- jQuery | one() with Examples
- jQuery | replaceWith() with Examples
- jQuery | removeProp() with Examples
- jQuery | resize() with Examples
- jQuery | replaceAll() with Examples
- jQuery | removeAttr() with Examples
- jQuery | scrollLeft() with Examples
- jQuery | submit() with Examples
- jQuery | scrollTop() with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



