get height of a div and set the height of another div using it

后端 未结 5 1093
孤街浪徒
孤街浪徒 2021-01-14 08:20

I have two divs, neither have a height set in css, as I want to take whatever height they end up as and set the other div to be that height.

The javascript I have is

5条回答
  •  佛祖请我去吃肉
    2021-01-14 08:30

    Use offsetHeight - http://jsfiddle.net/HwATE/

    function fixHeight() {
        var divh = document.getElementById('prCol1').offsetHeight; /* change this */
        document.getElementById('prCol1').innerHTML = '
    • ' + divh + '
    '; document.getElementById('prCol2').style.height = divh + 'px'; }

提交回复
热议问题