Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed help setting div in table height using Javascript
    primarykey
    data
    text
    <p>I am trying to set the div to a certain height inside an empty table cell to set the cell to 100% height. (The whole page consists of just the table with no padding.)</p> <p>Here is some relevant code:</p> <pre><code>&lt;table border="0" width="100%"&gt; &lt;tr&gt; &lt;td class="boxmiddleleft"&gt;&lt;/td&gt; &lt;td class="boxmiddlecenter"&gt;&lt;script language="javascript" src="includes/clock.js"&gt;/*clock*/&lt;/script&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="boxbottomleft"&gt;&lt;script language="javascript" src="includes/windowsize.js"&gt;&lt;/script&gt;&lt;div id="divbottomresize"&gt;&lt;/div&gt;&lt;/td&gt; &lt;td class="boxbottomcenter"&gt;&lt;button type="button" onclick="resizeheight();"&gt;Changed the window height? Reset by pressing this button.&lt;/button&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p>(With the div im trying to change height called '#divbottomresize')</p> <p>And the JavaScript I am using for this:</p> <pre><code>var element = "divbottomresize"; function resizeheight(element) { var height = 0; var body = window.document.body; if (window.innerHeight) { height = window.innerHeight; } else if (body.parentElement.clientHeight) { height = body.parentElement.clientHeight; } else if (body &amp;&amp; body.clientHeight) { height = body.clientHeight; } element.style.height = ((height - element.offsetTop) + "px"); } </code></pre> <p>If you have any idea what I am doing wrong please could you tell me. Alternatively if you find other code that does what I want feel free to paste or link me. (I do not want to use jQuery if possible.)</p> <p>When I run the code in Chrome and go to 'Inspect Element' I get the error:</p> <blockquote> <p>windowsize.js:12Uncaught TypeError: Cannot read property 'style' of undefined on the line element.style.height = ((height - element.offsetTop) + "px");</p> </blockquote> <p>EDIT: I have changed <code>var element = "divbottomresize";</code> to <code>var element = document.getElementById("divbottomresize");</code> as someone helpfully suggested. This still does not work and I get the same error and no height change.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload