Skip to content
Advertisement

Change div height back to dynamic

I have the code below to change the height of a div to equal that of its parent.

JavaScript

The problem is that the height of the child element #infocol, is no longer dynamic if i load new content inside of it. Is there a way to make the child element dynamic again after i have set the height with the above code?

I have tried to reconfigure its height after the content is loaded with the same code, but so far that hasn’t worked.

Advertisement

Answer

There is a way you can solve this issue using ResizeObserver

However, note that it’s not supported in some browsers, check the page I’ve linked for further details. Here is a working example:

JavaScript
JavaScript
JavaScript

Though, I suggest before implementing it like that, that you look into how flex works or simply even min-height might be the proper tool for the issue here. If you’re out of options, feel free to use ResizeObserver, but it’s considered an exotic solution!

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement