Example of has () method usage in jQuery, jqueryhas
This document describes the usage of the has () method in jQuery. Share it with you for your reference. The specific analysis is as follows:
This method retains matching elements that contain specific offspring.
The. has () method creates a group of matched objects from the original jQuery object.
By deleting the selected parameter, the method traverses the original object's descendants, and the objects containing matched descendants are retained.
Syntax structure 1:
Copy codeThe Code is as follows: $ (selector). has (expr)
Parameter List:
| Parameters |
Description |
| Expr |
String selector. |
Instance code:
Copy codeThe Code is as follows:
<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "UTF-8">
<Meta name = "author" content = "http://www.bkjia.com/"/>
<Title> helping customers </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>
</Head>
<Body>
<Div>
<Ul>
<Li> <span> HTML area </span> </li>
<Li class = "js"> Javascript area </li>
<Li> Div + Css area </li>
<Li> Jquery area </li>
</Ul>
</Div>
</Body>
</Html>
Match the li element containing the span element and set the font color to green.
Syntax structure 2:
Copy codeThe Code is as follows: $ (selector). has (element)
Parameter List:
| Parameters |
Description |
| Element |
Contains DOM elements. |
Instance code:
Copy codeThe Code is as follows:
<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "UTF-8">
<Meta name = "author" content = "http://www.bkjia.com/"/>
<Title> helping customers </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>
</Head>
<Body>
<Div>
<Ul>
<Li> <span> HTML area </span> </li>
<Li class = "js"> Javascript area </li>
<Li> Div + Css area </li>
<Li> Jquery area </li>
</Ul>
</Div>
</Body>
</Html>
Match the li element containing the span element and set the font color to green.
I hope this article will help you with jQuery programming.