Try this, essentially you need to get the img source and paste it into the modal "";
First, you must specify the identifier of the image from which you want to get the source, in order to simplify its extraction, and also make sure that more than one image is not associated with the class.
<img id="img-thumbnail" class="img-thumbnail" src="" data-def-dd="pic" id="pic" name="pic">
Secondly, the function should be adjusted as follows:
function loadImage(){ // get the src of the image var image_src = $("#img-thumbnail").attr('src'); // assign it to the modal body $("#photo_modal").attr('src',image_src); }
Secondly, you can execute this code when loading the page:
Option 1:
jQuery(document).ready(function($){ loadImage(); });
Option 2:
You can perform this function when loading a modal, there may be a lag, because it must be loaded.
$('#img_modal').on('show.bs.modal', function (event) { loadImage(); });
Hope this helps.
source share