javascriptwordpressmouseenter

Javascript in DIVI : mouseenter does not work


I am creating a website for a client using Divi on WordPress.

I need to add some js code to create a mouseenter effet in order to change a logo to a Qr code.

There is the code :

    window.onload = function(){
        let wechatLogo = document.querySelector('#wechat img');
        wechatLogo.addEventListener('mouseenter', e => {
            wechatLogo.src = "/wp-content/uploads/2020/10/微信图片_20201017141208-1.jpg";
    });
    }

It does nothing on the front and there is not any errors.

I need probably your helps.

Thanks a lot.


Solution

  • Try with wechatLogo.srcset

    window.onload = function(){
            let wechatLogo = document.querySelector('#wechat img');
            wechatLogo.addEventListener('mouseenter', e => {
                wechatLogo.srcset = "https://www.ateliersfrancochinois.com/wp-content/uploads/2020/10/微信图片_20201017141208-1.jpg";
        });
       }