First
Gets the first DOM element in the current collection of objects.
// returns the first Div object (Zepto object) // equivalent to $ ("div"). EQ (0);
It corresponds to the last
Last
Gets the last DOM element in the current collection of objects.
// returns the last Div object (Zepto object) // equivalent to $ ("div"). EQ (-1);
Both methods do not receive any parameters.
Personally, calling the IsObject method is useless because the Zepto object collection contains DOM elements. Maybe I'm ignorant of it--
Awakened by the great God. This might be for this scenario.
Get
Gets an element of the current object collection corresponding to the subscript, the passed parameter is an int subscript, and if the parameter is not passed in, the object is converted to an ordinary array and returned;
$ ("div"). Get (0); // No. 0 One. (DOM object, not Zepto object)//
The difference between this method and the EQ method is that the EQ returns the Zepto object, and get returns the DOM object, $ (). Get (0) is equivalent to $ () [0];
Slice is [].slice ();
Changes before and after objects that use get and do not pass in parameters:
Has:
The passed-in parameter is a selector string or a node that returns an object that contains the parameters for the child node of the object collection.
// returns all objects in the collection that contain a label
Either pass in a selector or pass in a node as a parameter
// returns an object in the collection that has children as #link
First, the filter method loads a child with a return value of true into a collection.
In the filter method, we differentiate by judging whether the selector is an object, or if it is an object, call the Contains method to determine whether selector belongs to this.
Otherwise, the Find method is called through the current object and selector is passed in, and the size method is called to get count (the filter automatically converts the return value to type bool).
Parent
Gets all the immediate parent nodes of the collection of objects. You can pass in a selector, leaving only the parent node that matches the selector.
$ ("P"). parent (); // Gets the parent node of all P tags ("P"). Parent (". Ads"); // Gets the parent node of all P tags classname the node that contains the. Ads
The Pluck method returns an array whose parameters are a string, the property name, and the value returned by the property that the calling object corresponds to;
Then passed the Uniq method, the method did a de-processing;
The outermost method filtered, if the second parameter selector is not empty, the filter method is called through the first argument and the second argument is passed to the filter method, otherwise the first argument is returned directly.
Parents:
Gets all the parent nodes of all objects. Until the HTML tag ends. You can pass in a parameter as a selector filter;
The parameter can only be a selector string;
The returned collection does not appear duplicate elements;
If you want to remove the immediate parent of the element, use parent;
If you want to remove the first parent node that meets the filter criteria, use closest.
$ ("P"). parents (); // get all P tags for all parent nodes $ ("P"). Parents (". Ads"); // gets all the parent nodes of all P tags classname the node that contains ads
Use parents if you do not pass in a parameter, it will always contain a body as well as an HTML element;
The method first declares an array to hold the DOM element and assigns this to the nodes variable;
Use a while loop with conditions of nodes.length > 0;
Within the loop, assigning a value to nodes via $.map, the map method internally assigns node to the parent node
Then determine if the node is not document and the node does not exist in the ancestors array, push the node to the array and return to node.
So the condition of the loop stop is that when node is the document.
Finally, the filtered method is called and returned.
Siblings:
Gets all the sibling nodes of the object. The parameter can be a selector string, such as an incoming parameter, filtered by the selector.
$ ("P"). siblings (); // gets the sibling label for all P tags $ ("P"). Siblings (". Ad"); // all of the P-tags of the sibling classname contain the elements of the ad
The DOM elements obtained through siblings are duplicated.
The method internally uses a children method.
The method internally takes the parent node of the element and passes in the children method, returning the child node of the parent node of the element, equivalent to all of its sibling nodes and itself.
Call the filter method from the return collection.
And all nodes except themselves are returned.
Finally, through the filtered method to filter, return;
Note that the elements obtained by the siblings are repeated, repeated, and repeated (re-say three);
Like this, the script tag appears two times;
OK, here we go. Write blog Practice language expression ability, feel oneself can understand, or say not good, tangled ing ...
Learning Zepto.js (Object method) [6]