Example of the is () method usage in jQuery, jqueryis

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.