As Bohoaush says - use JSON for data.
I made for update texts, image paths, css properties and classes a simple universal function that uses jQuery:
function dataScalarUpdate() {
//Update texts, images, css properties and classes along incoming JSON data
console.log('dataScalarUpdate');
for (var key in jsonData['scalar']) {
var obj = jsonData['scalar'][key];
switch (obj.par) {
case "text": //Value for text field
$(obj.id).html(obj.val);
break;
case "img": //Path to image
$(obj.id).attr({"src" : obj.val.replace('.tga','.png'), 'onerror' : "this.style.display='none'", 'style' : 'display:flex'});
break;
case "class": //Add class and remove all existing classes
$(obj.id).attr('class', obj.val);
break;
case "+class": //Add class
if (obj.val != '') {$(obj.id).addClass(obj.val)};
break;
default: //Any css property e.g. background-color, height etc...
$(obj.id).css(obj.par,obj.val);
}
}
}
I will assign an ID to each object whose property I will change in html. I can also assign a class to a group of objects whose properties I will change at once (For instance background color of divs for home or away etc.)
My data object then looks like this:
var jsonData = //This string comes from CG ADD command - data
{"scalar":[
{"id":":root","par":"--color-home","val":"235, 235, 235 "},
{"id":":root","par":"--color-away","val":"4, 60, 220"},
{"id":"#home-short","par":"text","val":"CAN"},
{"id":"#away-short","par":"text","val":"SWE"},
{"id":"#home-flag","par":"img","val":"../../Images/Flags/CAN.png"},
{"id":"#away-flag","par":"img","val":"../../Images/Flags/SWE.png"},
{"id":"#home-score","par":"text","val":"4"},
{"id":"#away-score","par":"text","val":"1"},
{"id":"#main-time","par":"text","val":"19:48"},
{"id":"#period","par":"text","val":"3rd"},
]}
Using this simple mechanism I can change any property of any object in any html file which calls the dataScalarUpdate() function from update function.