开发者

detection of height doesn't work

开发者 https://www.devze.com 2023-03-18 23:07 出处:网络
I have this simple script: var o = document.getElementById(\"content\"); if (o.clientHeight == \"372开发者_如何学JAVA\") {

I have this simple script:

var o = document.getElementById("content");

if (o.clientHeight == "372开发者_如何学JAVA") {
  o.style.height = "328px";
  o.style.marginBottom = "44px";

} else {
  o.style.height = "214px";
  o.style.marginBottom = "32px";
}

but somehow the ELSE always executes, even if the initial height of my div is 372px... can anyone help me?


clientHeight takes padding into account. You may want to use scrollHeight, offsetHeight, or style.height, depending on your needs. Note that style.height does not return an integer like the others.

http://help.dottoro.com/ljcadejj.php


if clientHeight does return integer, try to remove quotes like this:

var o = document.getElementById("content");
    if(o.clientHeight==372){
    o.style.height="328px";
    o.style.marginBottom="44px";}
    else{o.style.height="214px";
    o.style.marginBottom="32px";}
0

精彩评论

暂无评论...
验证码 换一张
取 消