Return the HTML content of the next sibling of a list item:
document.getElementById("item1").nextSibling.innerHTML;
Try it Yourself »
The nextSibling
property returns the next node on the same tree level.
The nextSibling
returnes a node object.
The nextSibling
property is read-only.
nextSibling
returns the next sibling node: An element node, a text node, or a comment node.
Whitespace between elements are also text nodes.
The nextElementSibling Property
nextElementSibling
returns the next sibling element (ignores text and comments).
In the HTML DOM terminology:
Nodes are all nodes (element nodes, text nodes, and comment nodes).
Whitespace between elements are also text nodes.
Elements are only element nodes.
Siblings are "brothers" and "sisters".
Siblings are nodes with the same parent (in the same childNodes list).
Element Siblings are elements with the same parent (in the same children list).
childNodes returns child nodes (element nodes, text nodes, and comment nodes).
children returns child elements (not text and comment nodes).
nextSibling returns the next node (an element node, a text node or a comment node). Whitespace between elements are also text nodes.
nextElementSibling returns the next element (not text and comment nodes).
previousSibling returns the previous node (an element node, a text node or a comment node). Whitespace between elements are also text nodes.
previousElementSibling returns the previous element (not text and comment nodes).
element.nextSibling
node.nextSibling
Type | Description |
Node | The next sibling of the element.null if no next sibling exists. |
element.nextSibling
is a DOM Level 1 (1998) feature.
It is fully supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 9-11 |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!