The use instance of Get () method in jquery _jquery

Source: Internet
Author: User

This example describes the use of the Get () method in jquery. Share to everyone for your reference. The specific analysis is as follows:

This method can return an array that matches all the DOM elements in the collection or a DOM element of a specified index.
The index value starts at 0.

Description: as you can see from the above definition, This method converts the jquery object into a DOM object.

Grammatical structure One:

Copy Code code as follows:
$ (selector). Get ()

When there are no parameters, an array of all the matching DOM elements is obtained.

Instance code:

Copy Code code as follows:

<! DOCTYPE html>
<meta charset= "Utf-8" >
<meta name= "Author" content= "http://www.jb51.net/"/>
<title>get () function-cloud-dwelling community </title>
<script type= "Text/javascript" src= "Mytest/jquery/jquery-1.8.3.js" ></script>
<script type= "Text/javascript" >
$ (document). Ready (function () {
$ ($ (". Zhuanqu"). Get ()). CSS ("Color", "green");
})
</script>
<body>
<div>
<ul>
<li>asp Zone </li>
<li class= "Zhuanqu" >jsp zone </li>
<li>php Zone </li>
<li>asp. NET Zone </li>
</ul>
<ul>
<li>div+css Zone </li>
<li class= "Zhuanqu" >jquery zone </li>
<li class= "Zhuanqu" >javascript zone </li>
<li>html Zone </li>
</ul>
</div>
</body>

By using the $ (". Zhuanqu"). Get (), you can obtain an array of LI elements whose class name is Zhuanqu. If you look at an example, you might ask why you have to set up $ () on the outside, because you can use the CSS () method by getting the DOM object from the Get () method, which needs to be converted into a jquery object.

Grammatical structure two:

Copy Code code as follows:
$ (selector). Get (Index)

With parameters, gets a matching element specified in the array of all matching DOM elements.

Instance code:

Copy Code code as follows:

<! DOCTYPE html>
<meta charset= "Utf-8" >
<meta name= "Author" content= "http://www.jb51.net/"/>
<title>get () function-cloud-dwelling community </title>
<script type= "Text/javascript" src= "Mytest/jquery/jquery-1.8.3.js" ></script>
<script type= "Text/javascript" >
$ (document). Ready (function () {
$ ($ (". Zhuanqu"). Get (0)). CSS ("Color", "green");
})
</script>
<body>
<div>
<ul>
<li>asp Zone </li>
<li class= "Zhuanqu" >jsp zone </li>
<li>php Zone </li>
<li>asp. NET Zone </li>
</ul>
<ul>
<li>div+css Zone </li>
<li class= "Zhuanqu" >jquery zone </li>
<li class= "Zhuanqu" >javascript zone </li>
<li>html Zone </li>
</ul>
</div>
</body>

The parameter inside is the index of the DOM object in the array of Dom objects to get, and the index is zero-based.

I hope this article will help you with your 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.