Skip to content

Instantly share code, notes, and snippets.

@Ankhena
Created October 9, 2021 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ankhena/f14cc31225ec48ae8d859c162d706fd2 to your computer and use it in GitHub Desktop.
Save Ankhena/f14cc31225ec48ae8d859c162d706fd2 to your computer and use it in GitHub Desktop.
equalHeight vanilla javascript
const equalHeight = (selector) => {
const blocks = document.querySelectorAll(selector);
let maxHeight = 0;
let blockHight;
blocks.forEach(block => {
block.style.setProperty('height', 'unset');
})
blocks.forEach(block => {
blockHight = block.clientHeight;
if (blockHight > maxHeight) {
maxHeight = blockHight;
}
})
blocks.forEach(block => {
block.style.setProperty('height', maxHeight + 'px');
})
}
equalHeight('.element');
window.addEventListener('resize', () => {
equalHeight('.element');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment