Skip to content

Instantly share code, notes, and snippets.

@firestar300
Created February 21, 2019 14:34
Show Gist options
  • Save firestar300/dfcfb4d9c3eea724a6c25f423cf9f3c0 to your computer and use it in GitHub Desktop.
Save firestar300/dfcfb4d9c3eea724a6c25f423cf9f3c0 to your computer and use it in GitHub Desktop.
get siblings method
export const getSiblings = element => {
// Setup siblings array and get the first sibling
const siblings = []
let sibling = element.parentNode.firstChild
// Loop through each sibling and push to the array
while (sibling) {
if (sibling.nodeType === 1 && sibling !== element) {
siblings.push(sibling)
}
sibling = sibling.nextSibling
}
return siblings
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment