Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter jleung1994

    (@jleung1994)

    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

    (@jleung1994)

    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.