Created
February 21, 2019 14:34
-
-
Save firestar300/dfcfb4d9c3eea724a6c25f423cf9f3c0 to your computer and use it in GitHub Desktop.
get siblings method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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