skip to Main Content

The background image of my landing needs to be changed when the button is clicked.

I´m a newbie on wordpress and don´t know how the background image on the landing could be changed.

I know that there is a possibility to work with JavaScript but I can´t find my button in the editor. Could someone help me step to step so that I can change the background image with other random images that I could use.

2

Answers


  1. Sorry, if you were using something like html then I could help.

    Login or Signup to reply.
  2. const yourButton = document.querySelector('#your-button-id');
    const element = document.querySelector('.element'); //element where you want to change background image
    const imageLink = 'www.domain.com/image-url.jpg'
    
    yourButton.addEventListener('click', (e) =>{
    e.preventDefault();
    element.style.backgroundImage = 'url(' + imageLink + ')';
    });
    

    change variables` selectors to yours, and if you click on button the primary background image will be changed

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search