Created
July 3, 2017 12:42
-
-
Save Jahans3/c4065d3997af5deb9513f1953674d8f3 to your computer and use it in GitHub Desktop.
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
const itemSelector = '[class*="tabs_item"]' | |
const findParents = ({ initialElement }) => { | |
let count = 0 | |
let element = initialElement | |
while (element.parentNode) { | |
count++ | |
element = element.parentNode | |
} | |
return { | |
element, | |
count | |
} | |
} | |
const tabItems = ({ tabsParent, itemSelector }) => { | |
const parent = document.querySelectorAll(tabsParent) | |
const children = parent.querySelectorAll(itemSelector) | |
const firstChild = children && children[0] | |
const { count: itemLength } = findParents({ initialElement: firstChild }) | |
return children.filter(element => { | |
const { count } = findParents({ initialElement: element }) | |
return count === itemLength | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment