Dave resolved for me on an earlier posting (
jQuery 1.10 | Match counter div class with element id to get length of element id children) a counter solution for one parent group which needed independant counting of div children lengths. I would need the same counting solution (if possible) for ten parent groups. Those ten parent groups will contain the same parent-children div classes and id, but only one group will be visible at any given time, so the hidden groups shouldn't affect the visible group div count, right?
It appears in my current modified setup, there is a counter conflict, meaning whatever children divs have been counted in the first visible parent group, whenever I hide that parent group and make visible another parent group, the counter keeps in memory what has previously been counted and displays the previous count in the new visible parent group at the same children counter divs location of the first parent group.
I tried counter empty(), html(''), even made certain that no id or no class be the same in all div children counters, but to no avail. It's like jQuery or the browser keeps in memory what has been counted first and displays that count in any other counter when a count is requested. I even tried emptying the DOM cache for the counter but no go. Below is sample code on what is going on:
- <div id ="GROUP-A" class="AllGroups"> // First* visible parent group counted, but now hidden.
- <div class="VCLA"> 3 </div> // Counter results are accurate.
- <ol id="VCLA" class="list">
- <li>SOME STUFF</li> // dynamically appended
- <li>SOME STUFF</li> // dynamically appended
- <li>SOME STUFF</li> // dynamically appended
- </ol>
- <div class="VCLB"> 2 </div> // Counter results are accurate.
- <ol id="VCLB" class="list">
- <li>SOME STUFF</li> // dynamically appended
- <li>SOME STUFF</li> // dynamically appended
- </ol>
- </div>
- <div id ="GROUP-B" class="AllGroups"> // Visible Parent group counted, with errors.
- <div class="VCLA"> 3 </div> // ERROR: Counter results should be 6, not 3 as in previous.
- <ol id="VCLA" class="list">
- <li>SOME STUFF</li> // dynamically appended
- <li>SOME STUFF</li> // dynamically appended
- <li>SOME STUFF</li> // dynamically appended
- <li>SOME STUFF</li> // dynamically appended
- <li>SOME STUFF</li> // dynamically appended
- <li>SOME STUFF</li> // dynamically appended
- </ol>
- <div class="VCLB"> 2 </div> // ERROR: Counter results should be 4, not 2 as in previous.
- <ol id="VCLB" class="list">
- <li>SOME STUFF</li> // dynamically appended
- <li>SOME STUFF</li> // dynamically appended
- <li>SOME STUFF</li> // dynamically appended
- <li>SOME STUFF</li> // dynamically appended
- </ol>
- </div>
*
First means the first group made visible after dom ready, not first as in index position of group.
Any working adaptation to the following code recently updated by Dave would be awesome:
- $("div[class^=VCL]").each(function(){
- var theList = $("#" + $(this).attr("class"));
- $(this).html(theList.children().length);
- });
Thx for helpers ~ dan