Skip to content

Instantly share code, notes, and snippets.

@Jahans3
Created July 3, 2017 12:42
Show Gist options
  • Save Jahans3/c4065d3997af5deb9513f1953674d8f3 to your computer and use it in GitHub Desktop.
Save Jahans3/c4065d3997af5deb9513f1953674d8f3 to your computer and use it in GitHub Desktop.
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