My HTML code is as follows:
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">Launch demo modal</button> <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title" id="myModalLabel">Modal title</h4> </div> <div class="modal-body"> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> </div> </div> </div> </div>
My JavaScript code is as follows:
<script type="text/javascript"> htmlData = ''; htmlData = 'Photos<a href="#" id="hotel_photo" data-hotel-code="nases">(Click to View)</a><br><br>'; htmlData += '<div class="imageHotel"></div>'; $('#myModal').find('.modal-body').html(htmlData); $(".imageHotel").hide(); $(document).on("click", "#hotel_photo", function(event){ $(".imageHotel").toggle(); event.preventDefault(); htmlData += '<div id="gallery_hotel">'; htmlData = '<img id="largeImage" src="http://www.workshop.rs/demo/gallery-in-4-lines/images/image_01_large.jpg" />'; htmlData += '</div>'; htmlData += '<div id="thumbs_hotel">'; htmlData += '<img src="http://www.workshop.rs/demo/gallery-in-4-lines/images/image_01_thumb.jpg" />'; htmlData += '<img src="http://www.workshop.rs/demo/gallery-in-4-lines/images/image_02_thumb.jpg" />'; htmlData += '<img src="http://www.workshop.rs/demo/gallery-in-4-lines/images/image_03_thumb.jpg" />'; htmlData += '<img src="http://www.workshop.rs/demo/gallery-in-4-lines/images/image_04_thumb.jpg" />'; htmlData += '<img src="http://www.workshop.rs/demo/gallery-in-4-lines/images/image_05_thumb.jpg" />'; htmlData += '</div>'; $('.imageHotel').html(htmlData); }); $('#thumbs_hotel').delegate('img','click', function(){ </script>
The demo is as follows: https://jsfiddle.net/oscar11/10td0yww/1/
When I click an image in the image list, the image does not change. Although I already called the hotel thumb.
When I do not use modal. he works
When I use modal. He does not work
Any solution to solve my problem?
Thank you very much
source share