Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding dynamic elements, and setting their width/height in a separate function
    primarykey
    data
    text
    <p>I'm creating a (parent) <code>&lt;section class="slide-item" data-id="slide-1"&gt;</code> element for each group of (child) items returned from a <code>jsonp</code> request. Each group is an object within an array:</p> <pre><code>array[ object, object, object ] </code></pre> <p>Each object contains attributes like the name, id, and, most importantly a nested array of <code>&lt;img /&gt;</code> elements that I'm appending to the corresponding <code>&lt;section&gt;</code> — the DOM looks something like this</p> <pre><code> &lt;section class="slide-item" data-id="slide-1"&gt; &lt;img src="http://lh5.ggpht.com/ySlk_p3UhTdXWyKXv=s1200" /&gt; &lt;img src="http://lh5.ggpht.com/ySlk_p3UhTdXWyKXv=s1200" /&gt; &lt;img src="http://lh5.ggpht.com/ySlk_p3UhTdXWyKXv=s1200" /&gt; &lt;/section&gt; </code></pre> <p>Ideally, what I would like to do is to create/add the DOM with one function, and then have another function that handles adding the width, height, and any other pertinent size/layout information. </p> <p>I know I can achieve it this way:</p> <pre><code> module.draft = function () { _.each( GROUP, function( id ) { BUILD.push( '&lt;section class="slide-item" style="width:' + widthVar + ';"&gt;&lt;/section&gt;' ); }); parentElement.append( BUILD.join( '' ) ); } </code></pre> <p>However, </p> <p>I would like to wait until the DOM is loaded, and then apply width height:</p> <pre><code> module.draft = function () { _.each( GROUP, function( id ) { BUILD.push( '&lt;section class="slide-item"&gt;&lt;/section&gt;' ); }); parentElement.append( BUILD.join( '' ) ); }; module.architect = function () { &lt;--- Doesn't work parentElement .find( '.slide-item' ) .width( widthVar ) .height( heightVar ); // # Other sizing stuff }; </code></pre> <p><strong>EDIT</strong></p> <p>A little more information: <code>GROUP</code> is the initial array of objects I mention in the beginning of the question: <code>array[ object, object, object ]</code> , <code>BUILD</code> is an empty array. </p> <p>I'm calling the functions like this: </p> <pre><code> module.init = function() { module.draft(); module.architect(); } </code></pre> <p>and then <code>$( document ).on( 'ready', _app.init );</code></p> <p>Also, I know I can make this work with <code>$( window ).on( 'load', _app.init );</code> but, it's not ideal.</p>
    singulars
    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