<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Example of getting width and height of element inside invisible container with prototype.js</title>
    <script type="text/javascript" src="js/prototype-1.6.0.3.js"></script>
    <style type="text/css">
      div.code { 
        white-space:pre;
        font-family: "Lucida Console","Courier New", monospace;
        font-size: 90%;
      }
      div#getValueLinks a {
        margin: 1ex;
      }
      div#sources {
        margin-top: 2em;
      }
    </style>
    <script type="text/javascript">
    //<![CDATA[
      Event.observe(document,'dom:loaded', function() {
        $$('.hideOnLoad').invoke('hide');
      });

 Element.addMethods({
    getDimensionsRe: function (element) { //remove 'Re' to replace original getDimensions and use only this function
        element = $(element);
        var dimensions = {width: element.clientWidth, height: element.clientHeight}; 
        
        if ((dimensions.width || dimensions.height) == 0) { 
          // All *Width and *Height properties give 0 on elements with display none, 
          // or when ancestors have display none, so enable those temporarily 
          var restore = element.ancestors(function(element) { return !element.visible() }), 
          styles = []; 
          restore.push(element); 
        
          restore.each(function(r) { 
            styles.push({ 
              display: r.getStyle('display'), 
              position: r.getStyle('position'), 
              visibility: r.getStyle('visibility') 
            }); 
            r.setStyle({display: 'block', position: 'absolute', visibility: 'visible'}); 
          }); 
        
          dimensions = {width: element.clientWidth, height: element.clientHeight}; 
          restore.each(function(r, index) { 
            r.setStyle(styles[index]); 
          }); 
        } 
        return dimensions;         
        
    }//getDimensions
 });
    //]]>
    </script>
</head>
<body>
  <h1>Example of gathering selected radio button with help of prototype.js</h1>

  <h2> Example html </h2>
  <div id="formAndSource">
(hidden three boxes)
  <div id="formDiv">
<div id="topBox" style="width: 600px; height: 200px; display: none; background: red;">
    <div id="middleBox" style="width: 80%;  padding-top: 5em; margin: auto; height: 5em; background: green;">
        <div id="innerDiv" style="margin-left: 10px; margin-right: 3ex; background: blue;">
            #innerDiv without "display:none" but hidden cause "#topBox" has display:none set;
        </div>
    </div>
</div>
  </div>
  </div>
<hr/>
  <div id="getValueLinks" >
    <a href="#" onclick="alert($('innerDiv').getDimensions().width + ' x ' + $('innerDiv').getDimensions().height);">Alert the result of original getDimensions() </a>
    <a href="#" onclick="alert($('innerDiv').getDimensionsRe().width + ' x ' + $('innerDiv').getDimensionsRe().height);">Alert the result of modified getDimensions()</a>
    <a href="#" onclick="$('topBox').toggle();">Toggle top - invisible- div.</a>
  </div>  

<div id="sources">
  <a href="#formSource" onclick="$('formSource').toggle();">Show form source</a>
  <div id="formSource" class="hideOnLoad code">
&lt;div id=&quot;topBox&quot; style=&quot;width: 600px; height: 200px; display: none; background: red;&quot;&gt;
    &lt;div id=&quot;middleBox&quot; style=&quot;width: 80%;  padding-top: 5em; margin: auto; height: 5em; background: green;&quot;&gt;
        &lt;div id=&quot;innerDiv&quot; style=&quot;margin-left: 10px; margin-right: 3ex; background: blue;&quot;&gt;
            #innerDiv without &quot;display:none&quot; but hidden cause &quot;#topBox&quot; has display:none set;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
  </div>
  <a href="#scriptSource" onclick="$('scriptSource').toggle();">Show script source</a>
  <div id="scriptSource" class="hideOnLoad code">

 Element.addMethods({
    getDimensionsRe: function (element) { //remove &#039;Re&#039; to replace original getDimensions and use only this function
        element = $(element);
        var dimensions = {width: element.clientWidth, height: element.clientHeight}; 
        
        if ((dimensions.width || dimensions.height) == 0) { 
          // All *Width and *Height properties give 0 on elements with display none, 
          // or when ancestors have display none, so enable those temporarily 
          var restore = element.ancestors(function(element) { return !element.visible() }), 
          styles = []; 
          restore.push(element); 
        
          restore.each(function(r) { 
            styles.push({ 
              display: r.getStyle(&#039;display&#039;), 
              position: r.getStyle(&#039;position&#039;), 
              visibility: r.getStyle(&#039;visibility&#039;) 
            }); 
            r.setStyle({display: &#039;block&#039;, position: &#039;absolute&#039;, visibility: &#039;visible&#039;}); 
          }); 
        
          dimensions = {width: element.clientWidth, height: element.clientHeight}; 
          restore.each(function(r, index) { 
            r.setStyle(styles[index]); 
          }); 
        } 
        return dimensions;         
        
    }//getDimensions
 });
  </div>
</div>
</body>
</html>




