Reprint: https://www.cnblogs.com/ooo0/p/6278102.html
JS jquery get Element (parent node, child node, sibling node)
One, JS get Element (parent node, child node, sibling node)
varTest = document.getElementById ("Test"); varparent = Test.parentnode;//parent Node varChils = Test.childnodes;//All child nodes varfirst = Test.firstchild;//first child node varlast = Test.lastchile;//Last child node varprevious = test.previoussbiling;//Previous sibling node varNext = test.nextsbiling;//Next Sibling node
Two, jquery gets the element (parent node, child node, sibling node)
$("#test1"). parent ();//parent Node$("#test1"). parents ();//All parent Nodes$("#test1"). Parents (". Mui-content"); $("#test"). Children ();//All child nodes$("#test"). Children ("#test1"); $("#test"). contents ();//returns all contents of #test, including nodes and text$("#test"). Contents ("#test1"); $("#test1"). Prev ();//Previous sibling node$("#test1"). Prevall ();//before all sibling nodes$("#test1"). Next ();//Next Sibling node$("#test1"). Nextall ();//after all the sibling nodes$("#test1"). siblings ();//All sibling Nodes$("#test1"). Siblings ("#test2"); $("#test"). Find ("#test1");
Three, Element filter
//The following methods return a new jquery object that contains the filtered elements$("ul Li"). EQ (1);//Select an element in UL Li that matches the index order of 1 (that is, the 2nd Li Element)$("ul Li"). First ();//Select the first element to match in ul Li$("ul Li"). Last ();//Select the last element in UL Li to match$("ul Li"). Slice (1,4);//Select 2nd ~ 4 Elements$("ul Li"). Filter (": Even");//Select all odd order elements in UL Li
JS jquery get Element (parent node, child node, sibling node), element filter