jQZoom: innerzoom issue after remove() and img src change

jQZoom: innerzoom issue after remove() and img src change

August 22, 2026 · Illustrated author avatarBy Stefan Bogdanescu
jQZoom: innerzoom issue after remove() and img src change

Resolving jQZoom Innerzoom Issues After remove() and img src Change

As a senior developer, I understand how frustrating it can be when you’re trying to customize your Magento online store and encounter issues with the jQZoom plugin on product pages. Let’s dive into the problem you’re facing and find a solution step by step.

The Issue at Hand

You’ve created a custom product page where the main image uses the jqZoom plugin for zooming, while thumbnails generated by Magento change the main image on mouseover. However, after the initial load, the zoom function stops working when you switch between images in most browsers.

The key problem lies in how jQZoom is initialized and reinitialized after the main image changes. When you remove the jqZoom from the main image and append a new one with updated attributes, the plugin fails to correctly initialize the new image for zooming.

Understanding the Code

Let’s break down the relevant parts of your code:

  1. Initialization in the head:
<script>
  $('imgzoom').ready(function(){
    // jqZoom options and initialization code here
  });
</script>
  1. jqZoom function reinitialization:
function startzoom() {
  // jqZoom options and jQuery('.imgzoom').jqzoom(options) call here
}
  1. Magento-generated main image with jqZoom:
<p class="product-image product-image-zoom">
  <?php
    $imagehelper = $_helper->productAttribute($_product, $_img, 'image');
    echo $imagehelper;
  ?>
</p>
  1. Thumbnail loop with onmouseover function:
<script>
  function update_img<?php echo $i; ?>()
  {
    jQuery('.imgzoom').remove();
    jQuery('.product-image.product-image-zoom').append('<?php echo $imagehelper; ?>');
    // ...
    startzoom();
  }
</script>
<a href="#" onclick="popWin(..., return false;" title="...">
  <img onmouseover="update_img<?php echo $i; ?>()" src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile()); ?>" width="66" height="100" alt="..." />
</a>

The Root Cause

When you call jQuery('.imgzoom').remove(), it only removes the original <img> element from the DOM, but not the associated jqZoom code and styles added by jQZoom. As a result, when you append a new image with an updated src attribute, jQZoom fails to initialize the new image correctly, leading to the innerzoom issue.

The Solution Approach

To resolve this issue, we need to ensure that jqZoom is properly cleaned up before reinitializing it for the new main image. Here’s a step-by-step solution:

  1. Update the update_img function:

Instead of just removing the .imgzoom class from the old image, you should remove all associated data and styles added by jQZoom first. You can achieve this using the jqzoom('destroy') method provided by the plugin.

Here’s the updated code:

function update_img<?php echo $i; ?>()
{
  // Remove jqZoom from the old image
  jQuery('.imgzoom').jqzoom('destroy');

  // Remove the original <img> element
  jQuery('.imgzoom').remove();

  // Append the new image with updated src attribute
  jQuery('.product-image.product-image-zoom').append('<?php echo $imagehelper; ?>');

  // ...
  startzoom();
}
  1. Rename and reinitialize jqZoom:

After removing the old jqZoom instance, you need to rename the new image element that will be used for zooming. This is because the .imgzoom class selector is still active from the previous initialization.

Update your PHP code generated by Magento:

<p class="product-image product-image-zoom">
  <?php
    $imagehelper = $_helper->productAttribute($_product, $_img, 'image');
    echo str_replace('<img ', '<img class="new-imgzoom" ', $imagehelper);
  ?>
</p>

Then, in your startzoom function, initialize jqZoom using the new selector:

function startzoom() {
  var options = { /* Your options here */ };
  jQuery('.new-imgzoom').jqzoom(options);
}
  1. Ensure proper z-index for the zoomed image:

If you’re still experiencing issues with the zoomed window not appearing, check if there are any other elements on your page that have a higher z-index value than the jqZoom window.

To ensure that the zoomed window appears above all other elements, set its z-index to a high enough value in your stylesheet. For example:

.jqzoom {
  z-index: 9999 !important;
}

Conclusion

By carefully cleaning up the jqZoom instance before reinitializing it for the new main image and ensuring that the z-index is properly set, you should be able to resolve the innerzoom issue after removing and changing the src attribute.

Remember to test your solution across multiple browsers to ensure compatibility. If you still encounter issues, feel free to reach out or visit Laravel Company for further assistance in customizing your Magento store.

Happy coding!

Catalog Database Extensions SEO

Our network