This example describes the use of the has () method in jquery. Share to everyone for your reference. The specific analysis is as follows:
This method retains a matching element that contains a particular descendant.
The. has () method will re-create a matching set of objects from the original jquery object.
method by deleting the parameters, the descendants of the original object will be traversed, and objects containing matching descendants will be preserved.
Grammatical structure One:
Copy Code code as follows:
Parameter list:
| Parameters |
Describe |
| Expr |
The string selector. |
Instance code:
Copy Code code as follows:
<! DOCTYPE html>
<meta charset= "Utf-8" >
<meta name= "Author" content= "http://www.jb51.net/"/>
<title> Cloud-dwelling community </title>
<script type= "Text/javascript" src= "Mytest/jquery/jquery-1.8.3.js" ></script>
<script type= "Text/javascript" >
$ (document). Ready (function () {
$ ("Li"). has ("span"). CSS ("Color", "green")
})
</script>
<body>
<div>
<ul>
<li><span>html Zone </span></li>
<li class= "JS" >javascript zone </li>
<li>div+css Zone </li>
<li>jquery Zone </li>
</ul>
</div>
</body>
Matches the Li element that contains the span element and sets the font color to green.
Grammatical structure two:
Copy Code code as follows:
$ (selector). has (Element)
Parameter list:
| Parameters |
Describe |
| Element |
Contains the DOM element. |
Instance code:
Copy code code as follows:
<! DOCTYPE html>
<meta charset= "Utf-8" >
<meta name= "Author" content= "http://www.jb51.net/"/>
<title> Cloud-dwelling community </title>
<script type= "Text/javascript" src= "Mytest/jquery/jquery-1.8.3.js" ></script>
<script type= "Text/javascript" >
$ (document). Ready (function () {
$ ("Li"). has (document.getElementsByTagName ("span")). CSS ("Color", "green");
})
</script>
<body>
<div>
<ul>
<li><span>html Zone </span></li>
<li class= "JS" >javascript zone </li>
<li>div+css Zone </li>
<li>jquery Zone </li>
</ul>
</div>
</body>
Matches the Li element that contains the span element and sets the font color to green.
I hope this article will help you with your jquery programming.