12 Feb 2022

JavaScript variable for Changing CSS Height


I created a script that compares the heights of two items and adjusts the heights to match if one is less than the other. According to the console log, it is doing and recognising everything as intended, with the exception of adjusting the element height, which I assume is due to the fact that it is stored as a variable? Any assistance is much appreciated.

console.log("Script Start");

let divElement = document.getElementById("basic-calendar-card");
let style = window.getComputedStyle(divElement);
let height = style.getPropertyValue("height");

console.log('Basic calendar height = ' + height);

let divElementTwo = document.getElementById("list-calendar-card");
let styleTwo = window.getComputedStyle(divElementTwo);
let heightTwo = styleTwo.getPropertyValue("height");

console.log('List calendar height = ' + heightTwo);

if (height < heightTwo) {
 console.log('List calendar is bigger.') = heightTwo;
} else if (heightTwo < height) {
 console.log('Basic calendar is smaller.') = height;
} else {
 console.log('Same size.')

console.log("Script End");



19 Feb 2022

Hello maybe your browser is not compatible with the code.


It would be better to do this to update an attribute which will work on any main browser.

Can you test and make me know if it works better :)



document.getElementById('xxx').setAttribute("style","height :{height}");

© 2024 Copyrights reserved for