I need to compare two arrays, one with calendar days and one with registered days. When the registered day is corresponding to the value of the innerHTML
property of the array of div
it should paint the background of this div
black:
HTML
<div class="calendar">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
...
<div class="item">31</div>
</div>
<div class="dias-cadastrados">
<div class="day">4</div>
<div class="day">21</div>
...
</div>
JQuery
var evento = $(".day");
var eventos_arr = [];
var dias = $(".item");
for (var i = 0; i < evento.length; i++) {
eventos_arr[i] = evento[i].innerHTML;
var count = eventos_arr[i];
for (var y = 0; y < dias.length; y++) {
dias[count].style.backgroundColor = "#000"; // output: Uncaught TypeError: Cannot read property 'style' of undefined
};
};
The algorithm, besides not doing what it should, returns the error Uncaught TypeError: Cannot read property 'style' of undefined
on the line where I apply the style to div
.
What am I doing wrong?