I have an element, a div with ID homeColumnContain, which I need to set the height of based on one of its absolutely positioned children, an image element with an ID of homePictureID. My code looks like the following:
window.onload = function() {resizeColumns()};
window.onresize = function() {resizeColumns()};
function resizeColumns() {
document.getElementById("homeColumnContain").style.height = document.getElementById("homePictureID").style.height;
}
<div id="homeColumnContain">
<div class="homeColumn">
<!-- content -->
</div>
<div class="homeColumn">
<div id="slideContain">
<img src="images/image.jpg" id="homePictureID"/>
<!-- content -->
</div>
</div>
</div>
The code appears to do nothing. I've added listeners for both resizing the window and on window load, as these two events are when the height should be changed. I've tried moving my script around in the HTML document and this didn't work. I don't have a whole lot of formal training with JavaScript, so any feedback as to why this approach doesn't work would be great. I would prefer the solution to not divert to using jQuery.
Edit: I additionally tried some of the responses in the question that this was marked a duplicate of, and none of them solved my issue. Also, if relevant, I have a width defined in my homePictureID as 100%.