One, JS get Element (parent node, child node, sibling node)
var test = document.getElementById ("test");
var parent = Test.parentnode; Parent node
var chils = test.childnodes; All child nodes
var first = Test.firstchild; First child node
var last = Test.lastchile; Last child node
var previous = test.previoussbiling; Previous sibling node
var next = 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 content inside the #test, including the node and the text $ ("#test"). Contents ("#test1"); $ ("#test1"). Prev (); The previous sibling node $ ("#test1"). Prevall ();//Before all sibling nodes $ ("#test1"). Next ();//Next sibling node $ ("#test1"). Nextall (); After all brother nodes $ ("#test1"). siblings ();//All Brothers node $ ("#test1"). Siblings ("#test2"); $ ("#test"). Find ("#test1");
Three, Element filter
The following methods all return a new jquery object that contains the filtered element $ ( "ul li"). EQ (1);//Select the UL li matching element in index order 1 (that is, the 2nd Li Element) $ ("ul Li"). First () ; Select the first element in UL Li to match the $ ("ul Li"). Last ();//select UL Li to match the final element $ ("ul Li"). Slice (1, 4);//Select 2nd ~ 4 Elements $ ("ul Li "). Filter (": even "); Select all odd order elements in UL Li
JavaScript DOM node X