JavaScript DOM node X

Source: Internet
Author: User

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

Related Article

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.