Title: Cannot replace image with jQuery function
Last modified: August 31, 2016

---

# Cannot replace image with jQuery function

 *  [jleung1994](https://wordpress.org/support/users/jleung1994/)
 * (@jleung1994)
 * [10 years ago](https://wordpress.org/support/topic/cannot-replace-image-with-jquery-function/)
 * I cannot replace the product image with `$(‘a.yith_magnifier_zoom.woocommerce-
   main-image img’).error(function() {
    $( this ).prop( ‘src’, $bdefault_url ); }).
   prop(‘src’, $bnewsrc);`
 * The same code worked with another local developing website without this plugin.
 * [https://wordpress.org/plugins/yith-woocommerce-zoom-magnifier/](https://wordpress.org/plugins/yith-woocommerce-zoom-magnifier/)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [jleung1994](https://wordpress.org/support/users/jleung1994/)
 * (@jleung1994)
 * [10 years ago](https://wordpress.org/support/topic/cannot-replace-image-with-jquery-function/#post-7325877)
 * If I disable the plugin, this code worked well.
 *     ```
       j('a.woocommerce-main-image').error(function() {
               j( this ).attr( 'href', jdefault_url );
           }).attr('href', jnewsrc);
   
           j('a.woocommerce-main-image img').error(function() {
               j( this ).prop( 'src', jdefault_url );
           }).prop('src', jnewsrc);
   
           j('a.woocommerce-main-image img').error(function() {
               j( this ).prop( 'src-orig', jdefault_url );
           }).prop('src-orig', jnewsrc);
   
           j('a.woocommerce-main-image img').error(function() {
               j( this ).prop( 'alt', 'no image');
           }).prop('alt', jnewalt);
           j('a.woocommerce-main-image img').error(function() {
               j( this ).prop( 'title', 'no image');
           }).prop('title', jnewtitle);
   
           j('a.woocommerce-main-image img').error(function() {
               //j( this ).prop( 'srcset', jdefault_srcset );
               //jname = jdefault_name;
           }).attr('srcset', jnewsrcset);
       ```
   
 *  Thread Starter [jleung1994](https://wordpress.org/support/users/jleung1994/)
 * (@jleung1994)
 * [10 years ago](https://wordpress.org/support/topic/cannot-replace-image-with-jquery-function/#post-7325886)
 * still not working with updated code
    only ‘Alt’ and ‘Title’ seems to work, probably
   because there’s no conflict with frontend.js
 *     ```
       var jmain_img_zoom = j('a.woocommerce-main-image');
       var jmain_img_image = j('a.woocommerce-main-image img');
       // some code to generate new src, srcset
       jmain_img_zoom.error(function() {
               j( this ).prop( 'href', jdefault_url );
           }).prop('href', jnewsrc);
   
           jmain_img_image.error(function() {
               j( this ).prop( 'src', jdefault_url );
           }).prop('src', jnewsrc);
   
           jmain_img_image.error(function() {
               j( this ).prop( 'src-orig', jdefault_url );
           }).prop('src-orig', jnewsrc);
   
           jmain_img_image.error(function() {
               //j( this ).prop( 'srcset', jdefault_srcset );
               //jname = jdefault_name;
           }).prop('srcset', jnewsrcset);
   
           jmain_img_image.error(function() {
               j( this ).prop( 'alt', 'no image');
           }).prop('alt', jnewalt);
           jmain_img_image.error(function() {
               j( this ).prop( 'title', 'no image');
           }).prop('title', jnewtitle);
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Cannot replace image with jQuery function’ is closed to new replies.

 * ![](https://ps.w.org/yith-woocommerce-zoom-magnifier/assets/icon.svg?rev=3055439)
 * [YITH WooCommerce Product Gallery & Image Zoom](https://wordpress.org/plugins/yith-woocommerce-zoom-magnifier/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/yith-woocommerce-zoom-magnifier/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/yith-woocommerce-zoom-magnifier/)
 * [Active Topics](https://wordpress.org/support/plugin/yith-woocommerce-zoom-magnifier/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/yith-woocommerce-zoom-magnifier/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/yith-woocommerce-zoom-magnifier/reviews/)

## Tags

 * [change image](https://wordpress.org/support/topic-tag/change-image/)
 * [custom function](https://wordpress.org/support/topic-tag/custom-function/)
 * [product image](https://wordpress.org/support/topic-tag/product-image/)

 * 2 replies
 * 1 participant
 * Last reply from: [jleung1994](https://wordpress.org/support/users/jleung1994/)
 * Last activity: [10 years ago](https://wordpress.org/support/topic/cannot-replace-image-with-jquery-function/#post-7325886)
 * Status: not resolved