My goal is to utilize JavaScript for updating the CSS layout as the webpage loads. Below is the code I have been working on:
var container = 0; // Total UI Container
var containerTitle = 0; // Title Container
var article = 0;
var articleTitle = 0;
var divName = 0; // Temporary variable for article id names
var divNameT = 0; // Temporary variable for title id names
function setLayout(id) {
container = document.getElementById(id);
for(var x = 0; x < 18; ++x) {
// CREATE CONTAINER FOR ALL PANELS
divName = "articleCon"+ x;
article = document.createElement('div');
article.id = divName;
// SET UP CSS STYLE
article.style.cssText = 'height: 205px; width: 300px; background: red; margin-right: 20px; margin-bottom: 20px; display: block; float: left;';
setNewsTitle(count,divName); // Call function to set Title Panel
container.appendChild(article);
}
}
function setNewsTitle(count,id) {
containerTitle = document.getElementById(id);
// CREATE CONTAINER FOR TITLE
divNameT = "articleTitle"+ count;
articleTitle = document.createElement('div');
articleTitle.id = divNameT;
// SET UP CSS STYLE
articleTitle.style.cssText = 'position: absolute; height: 45px; width: 100px; background: yellow; display: inline;';
containerTitle.appendChild(articleTitle);
}
Everything works fine when I compile my code without including the call to function setNewsTitle(count,id). However, the problem arises when this function call is included - the page shows up blank with no content displayed.
I attempted to attach screenshots for better clarity, but unfortunately, I do not yet have sufficient reputation to do so.