简体   繁体   中英

Change div height in Internet Explorer 7

I can't change the div height in Internet Explorer 7 with this code, that works in other browsers.

document.getElementById('my_div').setAttribute("style","height:1000px !important");
    var clientHeight = document.getElementById('my_div').clientHeight;

You need to change this line

document.getElementById('my_div').setAttribute("style","height:1000px !important");

by

document.getElementById('my_div').style.height = '1000px';

This is a complete running example:

 function changeDivHeight(){ var oldHeight = document.getElementById('my_div').clientHeight; console.log('old Height:', oldHeight); var val = document.getElementById('newHeight').value; document.getElementById('my_div').style.height = val + 'px'; var newHeight = document.getElementById('my_div').clientHeight; console.log('new Height:', newHeight); }
 #my_div{ background-color: #d1d1f1; width: 400px; height: 20px; }
 New height value <input id="newHeight" type="text" placeholder="New div height" /> <button onclick="changeDivHeight()">Change height</button> <div id="my_div"></div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM