Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
const div = document.createElement('div')
const div_w0 = div.cloneNode()
const div_w100 = div.cloneNode()
const div_flex = div.cloneNode()
div_w0.style.marginRight = '-100%'
div_w0.style.visibility = 'hidden'
div_w0.style.width = '100%'
div_w0.setAttribute('aria-hidden', true)
div_w100.style.width = '100%'
div_flex.style.display = 'flex'
div_flex.style.position = 'relative'
function matchHeights([...els]){
els.forEach(matchHeight)
}
function matchHeight(subject, {}, siblings){
const container = div_flex.cloneNode()
siblings.forEach(el => {
const clone = el.cloneNode(true)
const wrapper = (
el === subject
? div_w100 : div_w0
).cloneNode()
wrapper.appendChild(clone)
container.appendChild(wrapper)
})
subject.parentNode.replaceChild(container, subject)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment