The JQuery object in the JQuery object set is different from the DOM object. The JQuery object can be the DOM object encapsulation, but the JQuery object is not just the DOM object encapsulation, it can also represent its custom objects. Why do we need to get JQuery objects instead of using DOM objects? Because... syntaxHighlighter. the JQuery object in the JQuery object set is different from the DOM object. The JQuery object can be the DOM object encapsulation, but the JQuery object is not just the DOM object encapsulation, it can also represent its custom objects. Why do we need to get JQuery objects instead of using DOM objects? Because JQuery objects encapsulate DOM object operations, you can easily use JQuery object methods to operate internally encapsulated DOM objects without worrying about browser compatibility. JQuery functions, abbreviated as $, can have different usage 1. $ (DOM element) encapsulates a DOM element into a JQuery object. this is the usage of $ (this) mentioned above. 2. $ (DOM element array) 3. $ (JQuery object) cloning of the original JQuery object 4. $ (object) var foo = {foo: "bar", hello: "world"}; var $ foo = $ (foo); 5. $ () Create an empty JQuery object set 6. $ (selector [, context]) selector is the selector mentioned above. We can use this selector in an existing DOM object, Document or a JQuery object set. For example, $ (selector, context) is equivalent to $ (context ). find (selector) 7. jQuery (html [, ownerDocument]) parses html and adds it to ownerDocument. Note that When html contains multiple nodes, it will be processed to add it to ownerDocument. For example, wrap it first, remove the direct text, and remove,Labels. 8. jQuery (html, attributes) provides attributes for a simple element. Copy code $ ("", {"href": "baidu.com", text: "append", on: {click: function () {alert ("clicked ");}}}). appendTo ("li"); copy the code to manage object set elements. After constructing an initial object set, we can also manage the object set, such as merging object sets, filter object sets. 1. merge object set add (selector | elements | html | JQuery object) add (selector, context) to merge two object sets. The result object set is ordered in the DOM. Addback () 1.8 is added to replace the andSelf function. Combine the objects in this object set with the objects in the previous object set. 2. get sub-object set first () Get the first element last () in the object set get the last element eq (index) in the object set get the elements at the given position in the object set, count from 0, if it is negative, it starts from the last number. Slice (start [, end]) obtains the elements in the specified range in the object set, counting from 0. If it is negative, it starts from the back. 3. filter the object set filter (selector | element | function (index) | JQuery object). The Node not (selector | elements | function (index) | JQuery object) that meets certain conditions is left in the object set) remove nodes that meet certain conditions from the object set. 4. Get the child element or child element contents () of the object set to obtain all the text and node child elements of the object in the object set. Children ([selector]) obtains all node child elements of objects in an object set. If a selector exists, the child element must meet the selector condition. Otherwise, the child element of the find (selector | element | JQuery object) is not obtained to find all the elements that meet the condition in the child node of the object set. The following two parameter formats are added in version 1.6. Has (selector | contained element) obtains all objects in the object set that have child nodes that meet certain conditions. obtain the parent element of the object set or the parent element parent ([selector]) to obtain the parent element of all nodes of the object in the object set. If a selector exists, the parent element must meet the conditions of the selector, otherwise, parents ([selector]) is not obtained to obtain the ancestor elements of all nodes of the object in the object set. If a selector exists, the ancestor element must meet the selector conditions, otherwise, parentsUntil [selector [, filter] | element [, filter] is not obtained. For each object in the object set, the ancestor element is obtained in sequence, until an ancestor element meets the selector conditions. OffsetParent () obtains the ancestor element of each object in the object set in sequence until an ancestor element has the relative, absolute, or fixed position. Closest (selector [, context] | element | JQuery object) searches for elements that meet the conditions on its parent node from the beginning of the object, until one or the root node is found. The following two parameter formats are added in version 1.6. 6. Obtain the neighbor prev [selector] of the object set to obtain the first element of each object in the object set. If there is a selector, it is obtained when the previous element meets the conditions. Otherwise, it is not obtained. Next [selector] gets the next element of each object in the object set. If there is a selector, it is obtained when the previous element meets the conditions. Otherwise, it is not obtained. PrevAll [selector] gets all the elements that meet the selector conditions before each object in the object set. NextAll [selector] gets all the elements that meet the selector condition after each object in the object set. PrevUntil [selector [, filter] | element [, filter] obtains the elements before each object in the object set in sequence until an element meets the selector conditions. NextUntil [selector [, filter] | element [, filter] obtains the elements after each object in the object set in sequence until an element meets the selector conditions. Siblings ([selector]) obtains all the neighbor elements of each object in the object set that meet the selector conditions. 7. Other end () results are returned to the result object set after the last operation. After obtaining the object set, we can perform various operations on the object set, such as $ ("li" ).css ("background-color", "red "); set the background color of all objects in the $ ("li") object set. JQuery provides a large number of built-in methods for object sets. In addition, we can also use the following functions to customize operations on object sets: is (selector | element | function (index) | JQuery object) Whether there are elements in the test object set that meet certain conditions. The following three parameter forms are newly added in version 1.6. Map (callback (index, element) returns a result after performing a given operation on all objects in the object set. This function is usually used with get () to obtain a result set after a given operation. Each (function (index, element) performs the given operation on all objects in the object set.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.