Note that there are some explanatory texts on larger screens.

plurals
  1. PObuilding up an array of related data from divs
    text
    copied!<p>I need to loop through divs and their children and obtain data values to be accessed in an array. I can console log all the information correctly via index and each looping the children but I can't get it correctly into an array whereby each block is indexed, then another each loop gets the children within that block and pulls the data attributes from each of those .inner divs.</p> <p>Currently I do get an index of all the .block divs as arrays but within each of these rather than the 3 sets of data attributes (i.e as in the first .block having three .inner divs) it only pulls in the last set - e.g 7,56 whereas I need it to pull in 1,43 3,34 7,56</p> <p>here is my html</p> <pre><code>&lt;div id="wrapper"&gt; &lt;div class="block"&gt; &lt;div class="inner" data-a='1' data-b="43"&gt;&lt;/div&gt; &lt;div class="inner" data-a="3" data-b="34"&gt;&lt;/div&gt; &lt;div class="inner" data-a="7" data-b="56"&gt;&lt;/div&gt; &lt;/div&gt; &lt;div class="block"&gt; &lt;div class="inner" data-a='3' data-b="76"&gt;&lt;/div&gt; &lt;div class="inner" data-a="9" data-b="67"&gt;&lt;/div&gt; &lt;/div&gt; &lt;div class="block"&gt; &lt;div class="inner" data-a='5' data-b="33"&gt;&lt;/div&gt; &lt;div class="inner" data-a="4" data-b="22"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>and jQuery:</p> <pre><code>frame = $('.block'); blockNo = []; frame.each(function( index ) { blockNo.push(index); $(this).children().each(function() { cell = $(this); blockNo[index] = [cell.data('a'),cell.data('b')]; }); }); </code></pre>
 

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