I Apologize if there is already an answer, I found nothing usefull.
I am developing a little JS code with some blocks that need to change their html code. So I have a main object with 2 kinds of attributes :
My first version worked : i set some javascript event and methods, then my block content was changed.
Of course (!) I needed to modify the code to implements new features and now my method return html code but .innerHTML on my variables does not work anymore.
Let me show you some code and explain it
var AtelierScreen = function(ancre, dataJson){
if(!ancre.charAt) throw "Invalid string-dealer name type ('"+ancre+"') should be String";
if(ancre.length==0) throw "Invalid string-dealer name ('"+ancre+"') cannot be empty";
this.atelierContent;
this.operationMenu;
this.operationMenuContent;
this.operationRecap;
this.operationRecapContent;
this.create=function(obj,tagsuffix){
var tag = ancre+tagsuffix;
this.atelierContent.innerHTML += "<div id='"+tag+"'></div>";
var content = document.getElementById(tag);
if(!content) throw "Invalid html anchor using '"+tag+"' as an html id";
content.innerHTML=obj.getHtml();
return content;
}
try{
var dataObject = JSON.parse(dataJson);
this.atelierContent = document.getElementById(ancre);
if(!this.atelierContent) throw "Invalid html anchor using '"+ancre+"' as an html id";
// MENU
this.operationMenu = new OperationMenu(dataObject["dealer"],dataObject["operations"]);
this.operationMenuContent=this.create(this.operationMenu,"_menu");
this.operationMenuContent.innerHTML+="after init";
// RECAP
this.operationRecap = new OperationRecap();
this.operationRecapContent=this.create(this.operationRecap,"_recap");
this.operationMenuContent.innerHTML+="after recap init";
} catch(error){
throw "Error decoding json data :\n'"+error+"'\n\nJson =\n'"+dataJson+"'";
}
this.setSelectedModel=function(model){
this.operationMenuContent.innerHTML+="setSelectedModel";
var isTheSame = this.operationMenu.setSelectedModel(model);
if(!isTheSame) this.clearOperationItemFromRecap();
var temp = this.operationMenu.getHtml()
this.operationMenuContent.innerHTML=temp;
}
}
Quick overview
Here is what happen
I can still get the content attribute value atelierScreen.operationMenuContent.innerHTML; But I cannot insert text in dom. atelierScreen.operationMenuContent.innerHTML=""; does nothing.
Do I need to query the dom with document.getElement ... EACH TIME ? My previous version with dom elements as attributes was working...
I am missing something, this is so frustrating ;) Please help. Thanks
Ok, this is what i did
var AtelierScreen = function(ancre, dataJson){
try{
var dataObject = JSON.parse(dataJson);
this.atelierContent = document.getElementById(ancre);
if(!this.atelierContent) throw "Invalid html anchor using '"+ancre+"' as an html id";
var blocks = [
this.operationMenu = new OperationMenu(...),
this.operationRecap = new OperationRecap(...),
this.operationResult = new OperationResult(...)
];
for (var i = 0; i < blocks.length; i++) {
var block=blocks[i];
this.atelierContent.innerHTML += "<div id='"+block.tag+"'></id>";
}
for (var i = 0; i < blocks.length; i++) {
var block=blocks[i];
block.getContent().innerHTML = block.getHtml();
}
} catch(error){
throw "Error decoding json data :\n'"+error+"'\n\nJson =\n'"+dataJson+"'";
}
}