Utilizing Bootstrap 5.1.3 alongside Pure Vanilla JavaScript, I have successfully been able to populate the .modal-body
with content using the following code:
function showBSModal(modalid, inputid) {
var myModal = new bootstrap.Modal(document.getElementById(modalid), {});
var theValue = document.getElementById(inputid).value;
const parent = document.getElementById(modalid);
parent.querySelector(".modal-body").innerHTML = "Successfully Delete Uesr with ID: " + theValue;
myModal.show();
};
In this function, I dynamically pass the modalid
and the id of my input box (inputid
) to achieve the desired output.
https://i.sstatic.net/LQisD.jpg
I attempted to use myModal.querySelector
instead of parent.querySelector
, but it did not work since myModal.querySelector
is not recognized by the browser.
Question: Is there a more efficient method to accomplish the above task?