I have this in JS and the code below. I want to send the data-id into modal and also when closing the modal to dismiss the data-id. how can I do that using javaScript???
fetch("https://data.uk/api/" + $searchValue).then(
res => {
res.json().then(
data => {
if (data.length > 0) {
var temp = "";
temp += "<thead>";
temp += "<tr>";
temp += "<th>ID</th>";
temp += "<th>Force Name</th>";
temp += "<th>Details</th>";
temp += "</tr>";
temp += "</thead>";
temp += "<tbody>";
data.forEach((itemData) => {
temp += "<tr><td>" + itemData.id + "</td>";
temp += "<td>" + itemData.name + "</td>";
temp += "<td><a href='#' data-id='" + itemData.id + "' data-toggle='modal' data-target='#myModal'>More Detail</a></td></tr>";
});
temp += "</tbody>";
document.getElementById('data').innerHTML = temp;
}
}
)
}
)
and I want to get each data-id value into modal using this
$("myModal").on("show.bs.modal", function(e) {
var b = $(e.relatedTarget);
var r = b.data("id");
var modal = $(this);
modal.find("#me").text(r);
})
and this is my modal, I want when I open the modal to be able to capture the data-id and display it in id="me"
<div class="modal-body" id="modal-body">
<div class="row m-0">
<div class="col-4">
People name & twitter
</div>
<div class="col-8">
Descriptions
<h2 id="me"></h2>
</div>
</div>
</div>