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:
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.