The difference between get and EQ
. eq () Reduces the collection of matching elements, specifying the Index object precisely based on the index value. Get () gets the corresponding DOM element by retrieving the matching jquery object.
The same is the return element, so what is the difference between EQ and get?
eq Returns a jquery object, and get returns a DOM object . As an example:
$ ("Li"). Get (0). CSS ("Color", "red"); Error $ ("li"). EQ (0). CSS ("Color", "red"); That's right
The Get method essentially converts a jquery object into a DOM object, but the CSS belongs to the jquery constructor, and the DOM does not exist in this way, and if you need to use jquery, we have to write it this way:
var li = $ ("li"). Get (0); $ (LI). css ("Color", "red"); With $ packaging
Taking out the DOM object Li and then wrapping it again into a jquery object to call the CSS method is too cumbersome to write in 2 steps, so jquery provides us with a handy way to EQ ().
EQ () is implemented by turning the EQ method inside into a jquery object in the code above:
Eq:function (i) { var len = this.length, j = +i + (i < 0? len:0); Return This.pushstack (J >= 0 && J < len? [This[j]]: []);
The logic of implementing code above is the same as get, the difference is that through the pushstack produced a new jquery object.
jquery is thoughtful and can only produce a new object through the EQ method, but what if a collection object needs to be handled? So jquery provides a slice approach:
Grammar:
. Slice (start [, end])
Role:
Filters the matching set of elements according to the specified subscript range, and generates a new JQuery object.
Because it is an array object, it means that we can use Silce to directly take the value, so we can write the code for the collection object:
var arr = []arr.push (This.slice (Start[,end])) This.pushstack (arr)
This refers to the jquery object, because the jquery object is a collection of arrays, so we can take the number of collections directly from the native Silce method and then wrap them up.
Slice:function () { return This.pushstack (slice.apply (this, arguments));},
The difference between get and EQ in jquery