Reprint: https://lvwenhan.com/web-front/373.html
Native JavaScript methods:
var a = document.getElementById ("Dom"); Del_space (a); Clean space var b = a.childnodes;//Get all the child nodes of A; var c = a.parentnode;//get parent node of A; var d = a.nextsibling;//Get the next sibling section of a Point var e = a.previoussibling;//Get the previous sibling of a var f = a.firstchild;//Get the first child node of a var g = a.lastchild;//Get the last child of a Node
jquery Method:
Jquery.parent (expr)//Find the 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 is to find all ancestor elements, not limited to the parent element Jquery.children (expr)//Return all child nodes, this method will only return the direct child node, Does not return all descendant nodes jquery.contents ()//return all content below, including nodes and text. The difference between this method and children () is that including blank text, which is also returned as a jquery object, children () returns only the node Jquery.prev ()//returns to the previous sibling node, Not all Brothers node Jquery.prevall ()//Return all previous sibling nodes Jquery.next ()//return to the next sibling node, not all sibling nodes Jquery.nextall ()// Return all subsequent sibling nodes jquery.siblings ()//Return sibling nodes, no points before and after
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 returned result of Jquery.find () does not have the contents of the initial collection, such as $ ("P"), Find ("span"), which is the start of the P element, equivalent to $ ("p Span ").
JS or jquery How to get parent, child, sibling elements (including ancestor, grandchild, etc.)