Created
October 6, 2017 15:06
-
-
Save aderaaij/1ce696d3383b2e9f55cc9d111b5087c2 to your computer and use it in GitHub Desktop.
Get siblings in vanilla js
This file contains hidden or 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 function getSiblings(elem) { | |
var siblings = []; | |
var sibling = elem.parentNode.firstChild; | |
for ( ; sibling; sibling = sibling.nextSibling ) { | |
if ( sibling.nodeType === 1 && sibling !== elem ) { | |
siblings.push( sibling ); | |
} | |
} | |
return siblings; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment