Javascript banner.innerHTML += "<div class=’blocks’></div>" not working

I have a web page and I needed to add HTML elements in a loop. But it won't add the HTML elements.

My HTML Code

const banner = document.getElementsByClassName('banner');
const blocks = document.getElementsByClassName('blocks');

for(var i=1; i < 4; i++){
  banner.innerHTML += "<div class='blocks'></div>";
}
<section>
  <h2>Coming Soon</h2>
  <div class="banner">
    <div class="blocks"></div>
  </div>
</section>

But this is not working. Please help me to fix this



Read more here: https://stackoverflow.com/questions/65881693/javascript-banner-innerhtml-div-class-blocks-div-not-working

Content Attribution

This content was originally published by Hashan Athurugiriya at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: