How to use jquery has() method

藏色散人
Release: 2023-03-20 10:45:16
Original
1841 people have browsed it

The jquery has() method returns all elements that contain one or more elements that match the specified selector. The usage syntax of the has() method is "$(selector).has(element)", The element parameter specifies the selector expression or element that matches the element.

How to use jquery has() method

The operating environment of this tutorial: Windows 10 system, jquery3.2.1 version, Dell G3 computer.

How to use jquery has() method?

The has() method returns all elements that have one or more elements matching the specified selector.

Tip: If you need to select elements that have multiple elements within them, please use commas to separate them (see the example below).

Syntax

$(selector).has(element)
Copy after login

Parameters

element Required. Specifies a selector expression or element that matches elements.

Usage example:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("p").has("span").css("background-color","yellow");
});
</script>
</head>
<body>

<h1>欢迎来到我的主页</h1>
<p>我的<span>名字</span>叫 Donald。</p>
<p>我住在<span>Duckburg</span>。</p>
<p>我最好的朋友是 Mickey。</p>

</body>
</html>
Copy after login

[Recommended learning: jQuery video tutorial]

The above is the detailed content of How to use jquery has() method. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!