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 | :has() Selector with example
- Check if a jquery has been loaded or not
- How to check an element has certain CSS style using jQuery ?
- How to find which DOM element has the focus using jQuery?
- How to get the class of a element which has fired an event using JavaScript/JQuery?
- jQuery callbacks.has() Method
- jQuery | jQuery.fx.interval Property with example
- jQuery | jQuery.fx.off Property
- jQuery | jQuery.support Property
- jQuery | jquery Property
- jQuery | prepend() with Examples
- jQuery | dblclick() with Examples
- jQuery | offset() with Examples
- jQuery | children() with Examples
- jQuery | Hide/Show, Toggle and Fading methods with Examples
- jQuery | focusin() with Examples
- jQuery | Animation, Slide methods with Examples
- jQuery | change() with Examples
- jQuery | filter() with Examples
- jQuery | height() and innerHeight() 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.


