I believe most people will make mistakes in these two methods. You can view the API documentation carefully. Eq returns a jquery object, and get returns an array of html objects. For example:
Yu
Use eq to obtain the color value of the first p Tag:
$ ("P" ).eq(0).css ("color") // because eq (num) returns a jq object, therefore, you can use the jq method css to get the color value of the first p tag using get:
$ ("P "). get (0 ). style. color // because get (num) returns an html object, it is useless to use the traditional HTML object method. Of course, you can also get (num) and convert the object into the 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 returned jquery object is used to reduce the Matching Element Set to an element. The position of this element in the Matching Element Set is changed to 0, and the set length is changed to 1.
Get: an html object array is used to obtain a matching element. Num indicates the number of matched elements.
For example, html code
The Code is as follows:
For example, if we use the jquery selector $ ("li"), then we will have two li elements. How can I select only one of them?
$ ("Li: eq (0)" ).html () or $ ("li" ).eq(0).html () is the first li here we will get the li-1
$ ("Li: eq (1)" ).html () or $ ("li" ).eq(1).html () is the second li here we will get li-2
Next let's take a look at get. Because get returns html objects, we are here
$ ("Li"). get (0). style. color = 'red'
You can only use this method or convert the get returned object to a jquery object in the operation.
$ ("Li" ).get(0)).css ("color", 'red ')
Complete code
The Code is as follows:
New Document