Note that there are some explanatory texts on larger screens.

plurals
  1. POdynamically change height of div jquery on window resize
    primarykey
    data
    text
    <p>I am using the code from <a href="https://stackoverflow.com/questions/7821184/each-in-a-div-element-find-a-child-element-set-height-based-on-its-content">.each() in a div element, find a child element, set height based on its content (advanced?)</a> its working fine on page load but not working with window resize please help</p> <pre><code>$('#col-main &gt; div').each(function () { var tmpHeight = 0; $(this).find("h2").each(function() { tmpHeight = $(this).height() &gt; tmpHeight ? $(this).height() : tmpHeight; }); $(this).find("h2").height(tmpHeight); }); </code></pre> <p>Adding working code on page load from this code I get height of taller div (column) ".demographcont" in a row (".box") which i set to other divs in the row for same height ".demographcont". its worked for all rows. <img src="https://i.stack.imgur.com/edqKk.png" alt="on normal size"></p> <p>Not worked on window resize its reset the height and the height will come as per content <img src="https://i.stack.imgur.com/hSEOS.png" alt="window resize"></p> <p>after page refresh on window resize <img src="https://i.stack.imgur.com/1qpMq.png" alt="enter image description here"></p> <pre><code>/* code for adding height to div as per content */ function setHeight() { $('.box').each(function () { var tmpHeight = 0; $(this).find(".demographcont").each(function () { tmpHeight = $(this).height() &gt; tmpHeight ? $(this).height() : tmpHeight; }); $(this).find(".demographcont").height(tmpHeight); // alert(tmpHeight); }); } $(document).ready(function () { setHeight(); }); $(window).resize(function () { setHeight(); }); </code></pre> <p>Html code here </p> <pre><code>&lt;div class="box clearfix"&gt; &lt;div class="demographcont clearfix"&gt; &lt;div class="grid_12"&gt; &lt;div class="grid_5"&gt; &lt;label&gt; Date of Birth:&lt;/label&gt; &lt;/div&gt; &lt;div class="grid_7"&gt; 18/06/2013 &lt;/div&gt; &lt;/div&gt; &lt;div class="grid_12"&gt; &lt;p&gt; content1&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="demographcont"&gt; &lt;div class="grid_12"&gt; &lt;p&gt; content1&lt;/p&gt; &lt;p&gt; content1&lt;/p&gt; &lt;p&gt; content1&lt;/p&gt; &lt;p&gt; content1&lt;/p&gt; &lt;/div&gt; &lt;div class="grid_12"&gt; &lt;p&gt; content1&lt;/p&gt; &lt;p&gt; content1&lt;/p&gt; &lt;p&gt; content1&lt;/p&gt; &lt;p&gt; content1&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>.demographcont{ border:1px solid #006599; padding:0; line-height:20px; }</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.
 

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