function alignHeadersByHeight(table) { var maxHeight = 0; table.querySelectorAll('h1').forEach( element => maxHeight = Math.max(maxHeight, element.clientHeight) ) table.querySelectorAll('h1').forEach( element => element.style.height = maxHeight + 'px' ) console.log(maxHeight); } var table = document.getElementById("pbic"); alignHeadersByHeight(table);