Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Tree Walker: My solution

93 views
Skip to first unread message

David Ding

unread,
Feb 19, 2023, 5:53:44 PM2/19/23
to Intro to JavaScript
nextNode = function(node){
  if (node.firstChild !== null) {
    return node.firstChild;
  }
  if (node.nextSibling !== null) {
    return node.nextSibling;
  }
 
  while (node.parentNode !== null) {
    node = node.parentNode;
    if (node.nextSibling !== null) {
      return node.nextSibling;
    }
  }
  return node;
}
Reply all
Reply to author
Forward
0 new messages