Na egzaminie czasem trzeba dodać nowy element (li, p, wiersz tabeli) po kliknięciu przycisku.
createElement("li") → tworzy nowy elementelement.innerHTML = "tekst" → ustawia treśćlista.appendChild(element) → dodaje na koniec
function dodajA() {
let tekst = document.getElementById("produktA").value;
if (tekst === "") return; // nie dodawaj pustego
let nowy = document.createElement("li");
nowy.innerHTML = tekst;
document.getElementById("listaA").appendChild(nowy);
document.getElementById("produktA").value = ""; // wyczyść pole
}
const inputB = document.getElementById("produktB");
const listaB = document.getElementById("listaB");
document.getElementById("btnB").addEventListener("click", function() {
let tekst = inputB.value;
if (tekst === "") return;
let nowy = document.createElement("li");
nowy.innerHTML = tekst;
listaB.appendChild(nowy);
inputB.value = "";
});
document.getElementById("btnC").onclick = () => {
const tekst = document.getElementById("produktC").value;
if (!tekst) return;
const li = document.createElement("li");
li.innerHTML = tekst;
document.getElementById("listaC").appendChild(li);
document.getElementById("produktC").value = "";
};