Example of the is () method usage in jQuery, jqueryis
This document describes the usage of the is () method in jQuery. Share it with you for your reference. The specific analysis is as follows:
This method uses parameters to check Matching Element sets.
If at least one element matches the given parameter, true is returned; otherwise, false is returned.
Syntax structure 1:
Copy codeThe Code is as follows: $ (selector). is (expr)
Parameter List:
| Parameters |
Description |
| Expr |
String Value to match the selector expression of the current element set. |
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> is () function-helper's house </title>
<Script type = "text/javascript" src = "mytest/jQuery/jquery-1.8.3.js"> </script>
<Script type = "text/javascript">
$ (Document). ready (function (){
Alert ($ ("li"). parent (). is ("ul "))
})
</Script>
</Head>
<Body>
<Div>
<Ul>
<Li> div + css area </li>
<Li> jQuery area </li>
</Ul>
</Div>
</Body>
</Html>
The following code checks whether the parent element of the li element is ul. If yes, true is returned. Otherwise, false is returned.
Syntax structure 2:
Parameter List:
| Parameters |
Description |
| Element |
The DOM or jQuery element used to match the element. |
Instance code:
Instance 1:
Copy codeThe Code is as follows:
<! Doctype html>
<Html>
<Head>
<Meta charset = "UTF-8"/>
<Meta name = "author" content = "http://www.bkjia.com/"/>
<Title> is () function-helper's house </title>
<Script type = "text/javascript" src = "mytest/jQuery/jquery-1.8.3.js"> </script>
<Script type = "text/javascript">
$ (Document). ready (function (){
Alert ($ ("li"). parent (). is (document. getElementById ("parent ")))
})
</Script>
</Head>
<Body>
<Div>
<Ul id = "parent">
<Li> div + css area </li>
<Li> jQuery area </li>
</Ul>
</Div>
</Body>
</Html>
Example 2:
Copy codeThe Code is as follows:
<! Doctype html>
<Html>
<Head>
<Meta charset = "UTF-8"/>
<Meta name = "author" content = "http://www.bkjia.com/"/>
<Title> is () function-helper's house </title>
<Script type = "text/javascript" src = "mytest/jQuery/jquery-1.8.3.js"> </script>
<Script type = "text/javascript">
$ (Document). ready (function (){
Alert ($ ("li"). parent (). is ($ ("# parent ")))
})
</Script>
</Head>
<Body>
<Div>
<Ul id = "parent">
<Li> div + css area </li>
<Li> jQuery area </li>
</Ul>
</Div>
</Body>
</Html>
Syntax structure 3:
Use functions to traverse the collection of elements.
This function accepts an index parameter, which is the index of the element in the jQuery set. In a function, this indicates the current DOM element.
Parameter List:
| Parameters |
Description |
| Function (index) |
Defines the function that returns the is () matching value. Index is the index value of the current element in the Matching Element Set. |
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> is () function-helper's house </title>
<Script type = "text/javascript" src = "mytest/jQuery/jquery-1.8.3.js"> </script>
<Script type = "text/javascript">
$ (Document). ready (function (){
Alert ($ ("li "). parent (). is (function (index) {return $ ("ul "). attr ("id") = "parent "}))
})
</Script>
</Head>
<Body>
<Div>
<Ul id = "parent">
<Li> div + css area </li>
<Li> jQuery area </li>
</Ul>
</Div>
</Body>
</Html>
I hope this article will help you with jQuery programming.