For example:
Feiyu
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 use get to get the color value of the first p tag:
$("p ").get(0).style.color //Because get(num) returns an html object, the traditional HTML object method must be used, and the jq object is useless at this time. Of course, you can also get(num) and convert the object to a jq object before performing the operation:
$($("p").get(0)).css("color")----- -------------------------------------------------- ------------------
more eq
see:
http://api.jquery.com/eq/
--- -------------------------------------------------- ---------------------
more get:
see:
http://api.jquery.com/get/
eq: The return is a jquery object whose 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 length of the set becomes 1
get: is an array of html objects that is used to obtain one of the matching elements. num indicates which matching element is obtained.
For example: html code
< ul>
li-1
li-2
For example, we pass jquery selector $("li") Then we will have two li elements. How can I only select one of them?
$("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 look at get. Because get returns an html object, here we are
$("li" ).get(0).style.color='red'
Only used in this way or convert the object returned by get into a jquery object before operating
$($("li").get(0)).css ("color",'red') can
Complete code