skip to Main Content

I have images I photoshopped that are weather icons like a sun, cloud, rainy cloud, etc. On the Site I want to be able to click on them, and change the background image of the site, the Body background. But it doesn’t work, can’t click on the image, nothing happens. This is what I have so far, with #skyclear being the image ID, and clearsky being the css styling =>

$('body').addClass(bodyClass);

$('#skyclear').on('click', () => {
    bodyClass = 'clearsky'
})

2

Answers


  1. $('body').addClass(bodyClass);
    

    This should be in the onClick function. You should also consider removing any unnecessary classes inside of the onClick as well.

    Login or Signup to reply.
  2. I would just do it like this:

    $('#skyclear').on('click', function(){
        $('body').addClass('clearsky');
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search