As an example:
<p style= "Color:yellow" > Fei rain </p> use EQ to get the color value of the first P tag:
$ ("P"). EQ (0). CSS ("color")//Because EQ (num) Returns a JQ object, you can use the JQ method css to get the color value of the first P tag:
$ ("P"). Get (0). Style.color//Because getting (num) returns an HTML object, the JQ object is useless at this time using the traditional HTML object method. Of course, you can also convert objects to JQ objects after get (num):
$ ($ ("P"). Get (0)). CSS ("color")--------------------------------------------------------------------------
More EQ
See
http://api.jquery.com/eq/
--------------------------------------------------------------------------
More get:
See
http://api.jquery.com/get/
EQ: Return is a jquery object function is to reduce the set of matched elements to one element. The position of this element in the set of matching elements becomes 0, and the set length becomes 1.
Get: is an HTML object array function is to obtain one of the matching elements. Num represents the acquisition of the first few matching elements.
such as: HTML code
Copy Code code as follows:
<ul>
<li>li-1</li>
<li>li-2</li>
</ul>
For example, we go through the jquery selector $ ("li") then we will have two Li elements how do I just want to choose one?
$ ("Li:eq (0)"). HTML () or $ ("li"). EQ (0). HTML () is the first Li here we will get li-1
$ ("Li:eq (1)"). HTML () or $ ("li"). EQ (1). HTML () is the second Li here we will get li-2
Let's take a look at get because the get return is an HTML object so we're here
$ ("Li"). Get (0). style.color= ' Red '
The only way to use or convert a Get return object to a jquery object is to manipulate
$ ($ ("Li"). Get (0)). CSS ("Color", ' red ')
Complete code
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<script language= "JavaScript" src= "Js/jquery.js" ></script>
<script language= "JavaScript" >
<!--
$ ("document"). Ready (function () {
Alert ($ ("Li:eq (1)"). html ());//Display Li-2 alert ($ ("Li:eq (0)"). HTML ())
$ ("Li"). Get (0). style.color= ' Red ';
$ ($ ("Li"). Get (1)). CSS ("Color", ' red ')
})
-->
</SCRIPT>
</HEAD>
<BODY>
<ul>
<li>li-1</li>
<li>li-2</li>
</ul>
</BODY>
</HTML>