0

Im trying to make all my div class elements to lose all its content by replacing their current content with nothing "".

document.getElementsByClassName("sprint_column").innerHTML = ""; 

But nothing happens with the "sprint_column" when im trying to reach the class, However if i try to reach the IDs it works:

document.getElementsById("div3_Score").innerHTML = ""; 

Here is the code where the Ids and Classes is created:

<div class='sprint_column' id='div3_".$team."'>Sprint 1</div>

Is there any way to clear all content from a class with "getElementsByClassName" or do i have to loop through all ID elements and clear them one by one?

Solen
  • 93
  • 1
  • 1
  • 7

1 Answers1

0

getElementsByClassName returns an array of DOM elements. You need to iterate through them, e.g. via a for loop, and change the innerHTML one by one.

Oli Beatson
  • 811
  • 10
  • 22