EDIT:
After some repeated work using another method (createElement) I got my code to such an extent that it can correctly access the elements, however it only uses the parameters of the last banner created at the end of the function. Here is a snippet of what I have today.
function load() { var staffB = ["Admin", "GM", "Dev", "FM", "Lore", "App", "Magic", "Event"]; var table = document.createElement("table"); for (var staffI = 0; staffI < staffB.length; staffI = staffI + 2) { var row = document.createElement("tr"); var td = document.createElement("td"); var td2 = document.createElement("td"); var temp1 = staffB[staffI]; var temp2 = staffB[staffI + 1]; for (var i = 0; i < 10; i++) { td.innerHTML = '<img src=banners/' + staffB[staffI] + '.png height="auto" width="100%">'; td.onclick = function() { select (temp1) } td2.innerHTML = '<img src=banners/' + staffB[staffI + 1] + '.png height="auto" width="100%">'; td2.onclick = function() { select (temp2) } } row.appendChild(td); row.appendChild(td2); table.appendChild(row); } document.getElementById("staff").appendChild(table); }
For the first time sending here, my apologies in advance for being a complete piece.
So, for starters, Iโm working on a page to collect medieval banners for the community in which I participate, therefore, to facilitate the addition / removal of different banners in the future, I created a modular HTML system using "for". When it is created, it changes the names of the files to which it refers to the names in the array, so I only need to change the list and add the file. The HTML that it creates is a table so that I can insert images with two columns.
This table is then used for the selection menu according to which you select the banner / curtain rod. I have an identifier attached to each <tr> based on the banner inside (executed during HTML creation). Now I need to do this so that when I click on the selection, the displayed sample image changes. Inside the generated HTML, I created onclick = "select (Insert Banner Name Here)" to pass the banner information to the next function, which is the switch.
Later, I found out that from what I saw, the function passes the variable, not the word / data itself. I'm trying to think about how I can encode this so that when I call the function will know which banner was clicked. When I tested the code, it always returned [HTMLTableCellElement object].
In case I don't make sense, this image may help. (Apologies for the bright colors, they are there, so I see that different divs are easier).

Selected banners are on the right, and previews are on the left. The images on the right are inside the table in the div (where the scroll bar). This is where I try to call the switch function from.
If anyone knows the way this is possible, or the best way around this, I would love to help him.