getNextElement function

/ Published in: JavaScript
Save to your folder(s)

A JS function that returns the next element of a node. Argument: The node you want to know next element.

From book Dom Scripting by Jeremy Keith.

Copy this code and paste it in your HTML
  1. function getNextElement(node) {
  2. if(node.nodeType == 1) {
  3. return node;
  4. }
  5. if (node.nextSibling) {
  6. return getNextElement(node.nextSibling);
  7. }
  8. return null;
  9. }

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.