Home  >  Article  >  Web Front-end  >  The nearest related node access method of a node in javascript_javascript skills

The nearest related node access method of a node in javascript_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:40:091057browse

In JavaScript, for each node in the document, there is

parentNode - parent node

firstChild - the first child node

lastChild - the last child node

previousSibling - the immediately preceding sibling node

nextSibling - the immediately following sibling node

Five related nodes, these nodes may not exist , is null. For example, document does not contain parent nodes, and text node (TextNode) does not contain child nodes.

This allows you to take a short trip and visit some related nodes of the current node.

In addition, there are childNode[] (contains all child nodes) and children[] (contains only child nodes of type element node, excluding text node textNode).

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn