This is a little complicated to explain, but I'll try my best. I have a JSON file full of data that my javascript and HTML pull from, depending on what options you select.
Basically, the number of displayed items can be like 1-100. There is also a button that toggles show more or less info about each item. Each item will call on this function, to toggle the show more or show less.
// THIS VAR IS THE NUMBER OF ITEMS DISPLAYED (CAN BE 1-100)
var numberList;
function showSpellInfo(id) {
// ARRAYLIST FOR IDS AND RANDOM NUMBER AMOUNT
var numberList = [0];
var spellContentList = ["spellContent0"];
var showMoreButtonList = ["showMoreButton0"];
var showLessButtonList = ["showLessButton0"];
// BLUIDS THE ARRAYS
for (let i = 0; i < listNumber; i++){
var newVal = i + 1;
numberList.push(newVal)
spellContentList.push("spellContent" + newVal);
showMoreButtonList.push("showMoreButton" + newVal);
showLessButtonList.push("showLessButton" + newVal);
}
// BUTTON TO SHOW MORE INFO
for (let x = 0; x < numberList.length; x++)
if (document.getElementById(showMoreButtonList[x]).onclick = true){
document.getElementById(showMoreButtonList[x]).style.display="none";
document.getElementById(showLessButtonList[x]).style.display="inline-block";
document.getElementById(spellContentList[x]).style.display="block";
}
}
My issue is the when I click one button it opens up all of them.
What I want, is when I click on an ID for it only open up the info for that ID. The problem is could be 1 or 100 ids. Is there an easier way to do this am I making this too complicated?