3
I need to compare two arrays, one with calendar days and the other with registered days. When the registered day corresponds to the property value innerHTML
of the array of div
he must 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
in the line where I apply the style to div
.
What I’m doing wrong?
Your algorithm is coloring the background of the Divs with the day class, however I need it to change the color of the div with the item class that matches the number that is written in the Divs with the day class. You can fix that?
– João Paulo Saragossa
@Joãopaulosaragossa this is how you want: http://jsfiddle.net/b6hb2443/1/ ? in this case just change the classes.
– Sergio
Thank you very much!
– João Paulo Saragossa