JS jquery get Element (parent node, child node, sibling node), element filter

Source: Internet
Author: User

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

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.