Skip to content

Instantly share code, notes, and snippets.

@snowman-repos
Created February 6, 2014 08:11
Show Gist options
  • Save snowman-repos/8840117 to your computer and use it in GitHub Desktop.
Save snowman-repos/8840117 to your computer and use it in GitHub Desktop.
Traversing the DOM, without jQuery
# Getting the parent node
parent = document.querySelector("div").parentNode
# Getting the next node
next = document.querySelector("div").nextSibling
# Getting the previous node
next = document.querySelector("div").previousSibling
# Getting the first child element
child = document.querySelector("div").children[0]
# Getting the last child
last = document.querySelector("div").lastElementChild
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment