Recently, I have always encountered various fathers, sons, brothers and sisters in my work. I have to check it every time. This time I sort it out.
Let me give you some information first:
【JS acquisition method】
<div id = "dom">
<div></div>
<div></div>
<div></div>
</div> function dom(){ var a = document.getElementByIdx_x_x("dom"); var b = ; GetaAll children of var c = ; GetaParent node var d = ; GetaThe next brother node var e = ;GetaThe last brother node var f = ; GetaThe first child node var g = ; GetaThe last child node }
【JQuery acquisition method】
(expr) Find father node,Can be transferred inexprPerform filtering,for example$("span").parent()or$("span").parent(".class") (expr),Similar to(expr),But search for all ancestor elements,Not limited to parent elements (expr).Return all child nodes,This method will only return direct child nodes,No return of all descendants (),Return to all the following,Includes nodes and text。This method andchildren()The difference is that,Include blank text,Will be used as a jQueryObject return,children()Then only the node will be returned (), Return to the previous sibling node,Not all brother nodes (),Return all previous sibling nodes (), Return to the next sibling node,Not all brother nodes (),Return all subsequent sibling nodes (), Return to the sibling node,No distinction between front and back (expr),and(expr)Totally different。()It's from the beginningjQueryFilter out part of the object collection,and()Return results,There will be no content in the initial collection,for example$("p"),find("span"),Yes frompStart looking for elements,Equivalent to$("p span")