0

I have the following code:

<html><body>
<div id="1" style="display:none"></div>
<div id="2" style="display:none"></div>
<div id="3" style="display:none"></div>
<div id="4" style="display:none"></div>
<div id="5" style="display:none"></div>
</body></html>

<script>
var minutes_array = [];

for (var i = 0; i < 6; i++) {
  minutes_array.push(i);
}

minutes_array.forEach(myFunction);

function myFunction(item, index) {
  document.getElementById(item).style.display = 'flex';
}

</script>

I want to show all the five div's with this JavaScript code. But it isn't working. The div's don't show up. What am I doing wrong? Many thanks in advance.

T. Hægh
  • 109
  • 1
  • 9
  • 4
    Always check the console for errors before asking why things aren't working as expected. You have no elements with an ID of 0, so an error gets thrown – CertainPerformance May 19 '20 at 12:21
  • You need to fix your code, i < 6 ---> i < 5 and you should add document.getElementById(index+1).style.display = 'flex'; – Rebai Ahmed May 19 '20 at 14:24

0 Answers0