previousSibling vs previousElementSibling
previousSibling | previousElementSibling |
---|---|
Returns previous node, including elements, text, comments, etc. | Returns previous element node, excluding text and comments. |
Accessed via previousSibling property in DOM traversal. | Accessed via previousElementSibling property in DOM traversal. |
Supported Browsers:
The browser supported by nextSibling property are listed below:
HTML DOM nextSibling Property
The nextSibling property returns the next node at the same tree level, providing a node object. It’s read-only and navigates through sibling nodes within the document structure.
Syntax:
node.nextSibling
Return value:
Name | Description |
---|---|
Node | The nextSibling property returns the next sibling node or null if none exists. |
Note: next sibling node: element, text, or comment node; includes whitespace as text nodes between elements.