Dom Traversal method (based on jquery)

Source: Internet
Author: User

After you create a jquery object with $ (), you can modify the matching elements in the future by calling the following DOM traversal methods.

Filter elements

. Filter (selector) matches the selected element with the given selector selector

The. Filter (callback) callback function callback the selected element that returns True

. EQ (index) counts the index selected element starting from 0

. First () select element One in

. Last () Select the final element in the element

. Slice (start, [end]) The selected element in the given range, starting from 0

. Not (selector) elements in the selected element that do not match the given selector

. has (selector) the element in the selected element that has descendants that match the given selector

Descendant elements

. Find (selector) a descendant element that matches the given selector selector

. contents () Child nodes (including text nodes)

. Children ([selector]) child node, you can pass in an optional selector selector further filter

Sibling elements

. Next ([selector]) next sibling element adjacent to each selected element, you can pass in an optional selector selector further filter

. Nextall ([selector]) all sibling elements after each selected element, you can pass in an optional selector selector further filter

. Nextuntil ([selector], [filter]) after each selected element, up to but not including the first matching selector elements of the sibling element, you can pass in the optional Selector filter filter further

. prev ([selector]) the previous sibling element adjacent to each selected element can pass in an optional selector selector further filter

. Prevall ([selector]) all sibling elements before each selected element, you can pass in an optional selector selector further filter

. Prevuntil ([selector], [filter]) a sibling element that precedes, until, but does not contain the first matching selector element in each selected element, can pass in an optional selector filter for further filtering

. siblings ([selector]) all sibling elements, you can pass in an optional selector selector further filter

Ancestor elements

. parent ([selector]) for each selected element, you can pass in an optional selector selector further filter

. parents ([selector]) all ancestor elements of each selected element, you can pass in an optional selector selector further filter

. Parentsuntil ([selector], [filter]) all ancestor elements of each selected element, up to but not including the ancestor element of the first matching selector element, can pass in an optional selector filter for further filtering

. Closest (selector) The first element that matches the selector, the traversal path starts with the selected element, and the lookup in the ancestor node along the DOM tree

. OffsetParent () The parent element to which the first selected element is positioned (for example, by relative or absolute)

Collection operations

The. Add (selector) selected element, plus the element that matches the given selector

. Addback () The selected element, plus the set of elements that were previously selected in the internal jquery stack

Previously selected elements in the. End () internal jquery stack

. Map (callback) results after invoking the callback function callback for each selected element

. Pushstack (elements) The specified element

Manipulating the selected element

. is (selector) determines whether the matched element has an incoming selector match element

. Index () Gets the indexes of the matching elements relative to their sibling elements

The index (element) of the DOM node in the matching element corresponding to the specified element

$.contains (A, B) determine if DOM Node A contains DOM node B

. each (callback) iteration matches the element that executes the callback function for each element

. length gets the number of matching elements

. Get () Gets a list of DOM nodes corresponding to the matching element

. Get (Index) Gets the DOM node in the matching element that corresponds to the specified index

. ToArray () Gets a list of DOM nodes corresponding to the matching element

Dom Traversal method (based on jquery)

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.