i’m trying to delete particular row data on button click.
js code is below:
/* ========================|City Get|====================== */
const listcitydata = document.querySelector("#listcitydata");
var srno = 0;
var first = db.collection("citymaster").orderBy("cityname", "asc");
first.get().then(function (querySnapshot) {
querySnapshot.forEach(function (doc) {
srno++;
let tr = document.createElement('tr');
tr.setAttribute('data-id', doc.id);
listcitydata.innerHTML += "<td>" + srno + "</td> <td>" + doc.id + "</td> <td>" + doc.data().cityname + "</td> <td>" + '<input id="Button" class="btn btn-danger" type="button" value="Delete" onclick="DeleteCityMasterData()" />' + "</td> "
});
});
/* ========================|City Delete|====================== */
function DeleteCityMasterData(id) {
if (confirm("Are you sure you want to Delete City Name? ",id)) {
db.collection("citymaster").doc(id).delete().then(function () {
console.log("Document successfully deleted!");
window.alert("City Name Delete!");
}).catch(function (error) {
console.error("Error removing document: ", error);
});
}
else {
window.alert("Cancel!");
}
}
/* ==================================================================== */
how to pass parameter throw id (doc.id) to the delete function.