Last active
September 5, 2018 15:13
-
-
Save nathansmith/2f277e473dfc78866a143d8973b81dd9 to your computer and use it in GitHub Desktop.
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
// Gets siblings of element. | |
const getSiblings = (el) => { | |
// Array method. | |
const f = Array.prototype.forEach | |
// Get children. | |
const children = el.parentNode.children | |
// Set in loop. | |
const siblings = [] | |
// Loop through. | |
f.call(children, (item) => { | |
// Not element itself, nor text. | |
if ( | |
item !== el && | |
item.nodeType === 1 | |
) { | |
// Add to array. | |
siblings.push(item) | |
} | |
}) | |
// Expose array. | |
return siblings | |
} | |
// Export. | |
export default getSiblings |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment