JS and jquery Get the parent element, child element, sibling element method

Source: Internet
Author: User

Recently work has always encountered to take all kinds of Father son Ah brothers and sisters Ah, every time to check, this time to tidy up a internationals ~

"How to Get JS"

function dom () {
var a = document.getelementbyidx_x_x ("Dom");


var B = a.childnodes; Get all child nodes of a
var c = A.parentnode; Gets the parent node of a
var d = a.nextsbiling; Get the next sibling node of a
var e = a.previoussbiling; Get the previous sibling node of a
var f = a.firstchild; Get the first child node of a
var g = A.lastchild; Get the last child node of a

}

"How To get jquery"

Jquery.parent (expr) to find a Father node, you can pass in expr for filtering, such as $ ("span"). Parent () or $ ("span"). Parent (". Class")

Jquery.parents (expr), similar to jquery.parents (expr), but finds all ancestor elements, not limited to parent elements

Jquery.children (expr). Returns all child nodes, this method only returns a direct child node and does not return all descendant nodes

Jquery.contents (), returns all of the following, including nodes and text. The difference between this method and children () is that, including blank text, it will also be used as a

The jquery object returns, children () returns only the node

Jquery.prev (), return to the previous sibling node, not all sibling nodes

Jquery.prevall (), returns all previous sibling nodes

Jquery.next (), returns the next sibling node, not all sibling nodes

Jquery.nextall (), returns all subsequent sibling nodes

Jquery.siblings (), back to sibling nodes, no points

Jquery.find (expr) is completely different from jquery.filter (expr). Jquery.filter () is a partial filter from the initial set of JQuery objects, and the return result of Jquery.find () does not have the contents of the initial collection, such as $ ("P"), and find ("span"), from P element starts looking, equivalent to $ ("P span")

Check the site classification when publishing found, ok enough boring ~ ~

JS and jquery Get the parent element, child element, sibling element method

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.