So, I have a html calendar that I need to loop through and find elements within a week, and then compare weeks to find the week that has the largest amount of elements. My structure looks something like this:
<div class="week">
<div class="day">
</div>
<div class="day">
</div>
<div class="day">
<div id="unique-number" class="target-element"></div>
<div id="unique-number" class="target-element"></div>
<div id="unique-number" class="target-element"></div>
</div>
<div class="day">
</div>
<div class="day">
<div id="unique-number" class="target-element"></div>
<div id="unique-number" class="target-element"></div>
</div>
<div class="day">
</div>
<div class="day">
<div id="unique-number" class="target-element"></div>
</div>
</div>
<div class="week">
<div class="day">
</div>
<div class="day">
<div id="unique-number" class="target-element"></div>
</div>
<div class="day">
</div>
<div class="day">
</div>
<div class="day">
<div id="unique-number" class="target-element"></div>
</div>
<div class="day">
</div>
<div class="day">
</div>
</div>
So, the goal would be to loop through there and see that the first week has 6 target elements and the second week has 2 target elements.
Here is what I've tried so far:
var maxDay = new Array();
$('.week').each(function() {
maxDay.push($(this).children( '.target-element' ));
console.log( maxDay );
});
I've tried about a thousand variations of that, and no dice.
Any help would be much appreciated.
EDIT:
I probably should specify that my javascript was just the start of trying to build an array with the values for each week, to then compare using Math.max.apply(Math,maxDay);
, but the array is not building as I would hope, and either seem to put EVERY element of the whole calendar in the array, or nothing at all.
EDIT: I realized that I actually need to be targeting unique div IDs instead of just the .target-element. They are actually the same div, but for my purposes I want to get all the unique div id numbers, loop through those by week, so I can add a grid-row-start css position.
My goal is to get rid of all the empty space I'm having in my calendar event structure.
Its so close too! For some reason looping through each week has become a huge mental block for me.
I'm able to get all the unique divs doing this:
var b = new Array();
$('.inner-pto-cal').each(function () {
b.push($(this).parent().attr("id"));
//console.log( b );
});
I just want to get that per week, so I can then loop through per week to incrementally add to the grid-row-start, and then reset at the next week loop.
Currently this is what I have for the whole month that is working:
for (var i = 2; i < uniq.length; i++) {
$('#' + (uniq[i]) + '.pto-cal-link').each(function () {
//change the grid-row-position
$(this).css('grid-row-start' , ''+i );
console.log('#'+uniq[i]);
//console.log(q);
});
}