Hi
The data-image
attribute is used to store custom data associated with an element, and its value should typically be a string that represents some data related to that element.
If you want to change the source of an image dynamically using JavaScript based on the hover effect, you should directly manipulate the src
attribute of the image
Trythis updated code
<!-- HTML structure for the image and modal -->
<div class="product-thumbnail">
<img src="default_image.jpg" id="thumbnailImage" alt="Thumbnail Image" onmouseover="showLargeImage()">
</div>
<!-- Modal -->
<div class="modal" id="myModal">
<div class="modal-content">
<span class="close" onclick="closeModal()">×</span>
<img src="" id="largeImage" alt="Large Image">
</div>
</div>
<!-- JavaScript to handle the image change and modal display -->
<script>
function showLargeImage() {
// Get the thumbnail image element
var thumbnailImage = document.getElementById("thumbnailImage");
// Get the source of the thumbnail image
var thumbnailSrc = thumbnailImage.src;
// Set the source of the large image in the modal
var largeImage = document.getElementById("largeImage");
largeImage.src = thumbnailSrc;
// Display the modal
var modal = document.getElementById("myModal");
modal.style.display = "block";
}
function closeModal() {
// Hide the modal
var modal = document.getElementById("myModal");
modal.style.display = "none";
}
</script>
If you find this helpful kindly accept the answer thanks much.