Home >>jQuery Tutorial >jQuery has() Method

jQuery has() Method

jQuery has() Method

jQuery has() method in jQuery is used to returns all elements that have one or multiple elements inside of them, that matches the specified selector.

Syntax:
$(selector).has(element)

Parameter Values

Parameter Description
element It is a Required parameter and is used to specifies a selector expression or an element to match elements agains
Here is an example jQuery has() Method:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("p").has("span").css("background-color", "#34eb92");
});
</script>
</head>
<body>
<h1>Welcome to Phptpoint</h1>
<p>My <span>name</span> is Phptpoint</p>
<p>I live in <span>Noida</span>.</p>
<p>This is my First paragraph</p>
</body>
</html>

Output:

Welcome to Phptpoint

My name is Phptpoint

I live in Noida.

This is my First paragraph