The Node.nextSibling read-only property returns the node immediately following the specified one in their parent's childNodes, or returns null if the specified node is the last child in the parent element.


nextNode = node.nextSibling


Gecko-based browsers insert text nodes into a document to represent whitespace in the source markup. Therefore a node obtained, for example, using Node.firstChild or Node.previousSibling may refer to a whitespace text node rather than the actual element the author intended to get.

See Whitespace in the DOM and W3C DOM 3 FAQ: Why are some Text nodes empty? for more information.

Element.nextElementSibling may be used to obtain the next element skipping any whitespace nodes, other between-element text, or comments.


<div id="div-1">Here is div-1</div>
<div id="div-2">Here is div-2</div>

var el = document.getElementById('div-1').nextSibling,
    i = 1;'Siblings of div-1:');

while (el) {
  console.log(i, '. ', el.nodeName);
  el = el.nextSibling;


  The console displays the following:

     Siblings of div-1

      1. #text
      2. DIV
      3. #text
      4. SCRIPT


In the above example, #text nodes are inserted in the DOM where whitespace occurs between tags (i.e. after the closing tag of an element and before the opening tag of the next).

The possible inclusion of text nodes must be allowed for when traversing the DOM using nextSibling. See the resources in the Notes section.


Specification Status Comment
The definition of 'Node.nextSibling' in that specification.
Living Standard No change
Document Object Model (DOM) Level 2 Core Specification
The definition of 'Node.nextSibling' in that specification.
Obsolete No change
Document Object Model (DOM) Level 1 Specification
The definition of 'Node.nextSibling' in that specification.
Obsolete Initial definition

Browser compatibility

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
nextSiblingChrome Full support YesEdge Full support 12Firefox Full support YesIE Full support 8Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes


Full support  
Full support

See also