Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const getIndex = (th) => Array.from(th.parentElement.children).indexOf(th)
const getChildren = (i) => Array.from(document.querySelectorAll(`td:nth-child(${i + 1})`))
const setHiddenStyle = (node) => {
node.style.width = '1px'
node.style.overflow = 'hidden'
node.style.overflowWrap = 'normal'
}
const toggleHidden = (node) => {
if (node.style.length) {
node.style = {}
} else {
setHiddenStyle(node)
}
}
const handleClick = (e) => {
const i = getIndex(e.currentTarget)
getChildren(i).concat([e.currentTarget]).forEach(toggleHidden)
}
document.querySelectorAll('th').forEach(th => {
th.onclick = handleClick;
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment