I am creating a gauge (using the Gauge files from justGage) in js for every element I have in a JSON file. I want to dynamically create div elements for every element in the JSON and to set a different id for each of them. This is the code:
function loadDoc(){
for(var i = 0; i < data.length; i++){
let newDiv = document.createElement('div');
let divID = "gauge" + i, divClass = "200x160px";
newDiv.setAttribute("id", divID);
newDiv.setAttribute("class", divClass);
//console.log(divID);
var g = new JustGage({
id: "gauge" + i,
value: 62,
min: 0,
max: 100,
title: "Satisfaction"
});
}
}
The problem is that even though the id is gauge0, gauge1, etc., the function does not recognize it and it says that there is no div with the id gauge0, gauge1, etc. Why?
Thanks!