I am setting some objects on Firebase-database, and showing them on a HTML table with 'child_added' to dynamically add them as soon as they are added to the database, and there has to be a delete button on each row of the table, but I do not know how to make a working button to delete the corresponding database object.
I am dynamically making a table with information coming from a Firebase. database. I want a delete button on each row of my table which deletes the corresponding table from the database.
function vislag(snapshot) {
let nylag = snapshot.val();
let idrettRef = database.ref("idrett/" + nylag.Idrett);
idrettRef.once("value", function(snapshotIdrett) {
let idrettinfo = snapshotIdrett.val();
txtTabell.innerHTML += `
<tr>
<td>${nylag.navn}</td><td>${nylag.klasse}</td>
<td>${nylag.antall}</td><td>${idrettinfo.navn}</td>
<td>
<input type="button" value="delete ${nylag.navn}" onclick="deletelag()"></td>
</tr>`;
});
}
lag.orderByChild("Idrett").on("child_added", vislag);
function deletelag() {
databaseobjekt.remove()
}
I want the onclick function: deletelag() to delete the object from the Firebase database. How do I do that?