Firefox is a 0 solution when capturing the div's height with offsetheight

Source: Internet
Author: User

Firefox needs to get the height of the div, often need to use offsetheight, sometimes encounter offsetheight get to 0 of the phenomenon,
In the use of IE or Firefox, especially in the current div+css way, often do not define the height of Div, this is added div content, need to get the height of Div, often need to use the offsetheight.

In use, sometimes encounter offsetheight get to 0 of the phenomenon, but if you use a variety of JS Debugging Tools debugging, but also in the object to see the value (if the direct point to offsetheight is not worth, but if the object view is a value, The object is refreshed by a carriage return view in the debugger, so there is a value. )

Like the following fragments.
The code is as follows:

Copy Code code as follows:


<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">


<html>


<head>


<script language= ' JavaScript ' >


window.attachevent ("onload", function () {_resizescroll2 ();});


window.onresize=function () {winresize ();};


function _resizescroll2 () {


var html1 = ' <div id= ' divcj ' style= ' margin-top:15px;font-size:10px;width:400px; > '


+ ' <div style= ' float:left;width:50px; > Test </div> '


+ ' <div style= ' float:left;width:320px; >danielinbiti</div> '


+ ' </div> '


+ ' <div id= ' divcj2 ' style= ' margin-top:15px;font-size:10px;width:400px; > '


+ ' <div style= ' width:320px; >danielinbiti</div> '


+ ' </div> '


document.getElementById (' outer '). INNERHTML=HTML1;


document.getElementById (' divcj2 '). style.display= ' None ';


Alert (document.getElementById (' divcj2 '). offsetheight);


}


</script>


</head>


<body>


<div id= ' outer ' ></div>


</body>


</html>


If you get the height of the DIVCJ, you get 0 in onload. Because the DIVCJ under the float way layout.

At this point if the div is simple, you can use the hidden layer, such as the divcj2 here, the float removed, get the height and divcj as high.

Here is a key point is that the float layout in IE is no problem, but for Firefox it takes 0

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.