I have a " P Element". So the height of each element can be higher then the other. So I want that all height are the same height, but every the highest.
I get no errors but it not works.
const getHeightAndSetNewHeight = () => {
const k = document.querySelectorAll('.kamera');
k.forEach(e => {
if(Math.max(Number(e.offsetHeight))) {
e.style.height = `${e.offsetHeight}px`;
}
});
};
You need to loop through once, find the maximum, then loop through again once you have it.
const getHeightAndSetNewHeight = () => {
const k = document.querySelectorAll('.kamera');
let max = -Infinity;
k.forEach(e => {
if (max < e.offsetHeight) max = offsetHeight;
});
k.forEach(e => {
e.style.height = `${e.offsetHeight}px`;
});
};