js--Traversal DOM Tree

Source: Internet
Author: User

The first hair of the traversal DOM tree given by the JS Official document is:
Parent Node-ele.parentnode
Child node-ele.childnode
First child node-firstchild
Last child node-lastchild
Previous sibling node-previoussibling
Next sibling node-nextsibling
To get an element from a property:
document.getElementById (); -Through ID
document.getelementsby** ()-Returns an array via another property.
But there is one problem: most of the time you traverse a DOM tree to get an element node rather than a text node
So you can use the method to get the desired element node directly:
Parent Node-ele.parentelementnode
Child node-ele.children
First child element node-firstelementchild
Last child element node-lastelementchild
Last sibling element node-previouselementsibling
Next sibling element node-nextelementsibling
So suddenly feel Bang bang ~ ~ But the good things IE are not compatible AH (again damned IE)
These methods are not compatible with the IE browsers below IE8 ...
Only Ele.children this one is compatible in IE8 but it also treats annotations as element nodes.
So, in short, in any case in IE use or be careful for the wonderful ~ ~ ~

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.