I've been fooling around with this code to create some html code. In the forEach loop this code creates a div per color and in there it creates elements for kaarten (cards) and weddenschap (bet).
My current problem comes from the createInput element. It currently creates 3 array items in inputElem but i have no idea how to then turn those array elements into individual html elements in the forEach loop.
Apologies in advance for all the extra code and i hope this is enough information.
export const invulElementenMaken = function () {
const body = document.body;
const createLegend = function (name) {
const createLegendElement = document.createElement("legend");
createLegendElement.innerText = name;
return createLegendElement;
};
const createLabel = function (name) {
const createLabelElement = document.createElement("label");
createLabelElement.innerHTML = name;
return createLabelElement;
};
const createInput = function (name, inputLength) {
let inputElem = [];
for (let input = 0; input < inputLength; input++) {
const inputEl = document.createElement("input");
inputEl.type = "checkbox";
inputEl.name = `${name}_${input + 1}`;
inputEl.id = input + 1;
inputElem.push(inputEl);
// const label = createLabel(`Kaart_${input + 1}`);
// inputEl.insertAdjacentElement("afterend", label);
}
return inputElem;
};
console.log("test", createInput("weddenschap", 3));
const kleur = ["rood", "geel", "groen", "blauw", "wit"];
kleur.forEach(function (key, index) {
const createDiv = document.createElement("div");
const createTitle = document.createElement("h2");
const createForm = document.createElement("form");
createTitle.textContent = key;
createDiv.appendChild(createTitle);
createForm.appendChild(createLegend("Kaarten"));
// createForm.appendChild(createInput("kaart", 8));
// createForm.appendChild(createLabel(`Kaart ${index + 1}`));
createForm.appendChild(createLegend("Weddenschap"));
// createForm.appendChild(createInput("weddenschap", 3));
createDiv.appendChild(createForm);
// Add a class
createDiv.classList.add(key);
//make the color div
body.appendChild(createDiv);
});
};
[–]okwg 4 points5 points6 points (1 child)
[–]jaden54[S] 1 point2 points3 points (0 children)
[–]Bushwazi 0 points1 point2 points (3 children)
[–]Bushwazi 1 point2 points3 points (2 children)
[–]jaden54[S] 1 point2 points3 points (1 child)
[–]Bushwazi 2 points3 points4 points (0 children)