When I tried to match the width(178px) and height(178px) of my table to the width and height of a text area upon clicking a button, I encountered an issue. While setting the width works perfectly fine, the height is being set to only 17px. It seems like some sort of truncation is happening where 8 is sliced off from 178px—need assistance with this aspect. I have attempted using element.style.height, element.offsetHeight, element.clientHeight, and element.getBoundingClientRect().height, but all produce the same result. There are many posts on Stack Overflow discussing similar issues; most developers face problems with setting the height while the width works flawlessly for them. What could be causing this discrepancy? Thank you.
<p id="demo"></p>
<button onclick="chan()">change</button>
<script type="text/javascript">
function chan() {
var w=document.getElementById('num').getBoundingClientRect().width;
var h=document.getElementById('num').getBoundingClientRect().height;
document.getElementById("demo").innerHTML=w+" "+h;
document.getElementById('cache').style.width=w+"px";
document.getElementById('cache').style.height=h+"px";
}
</script>