Doug Molineux
Doug Molineux

Reputation: 12431

JQuery Not Working in Chrome

This code works properly in Firefox but not in Chrome, If you need more of the code I would be glad to provide it, a button changes a background image:

$(document).ready(function() {
var bg = 1;
$("#changePic").click(function () {
    if (bg == 1)
    {
        $("#outerWrapper").css("background-image","url(images/background-lodge1.jpg");
        bg=2;
    }
    else if (bg == 2)
    {
        $("#outerWrapper").css("background-image","url(images/background-lodge2.jpg");
        bg=3;
    }
    else
    {
        $("#outerWrapper").css("background-image","url(images/background-lodge.jpg");
        bg=1;
    }
  });
});

I'm not getting any errors in the Chrome Console. Thanks!

Upvotes: 0

Views: 2470

Answers (3)

bobince
bobince

Reputation: 536795

As an aside, you can really factor out a lot of that common code:

$(document).ready(function() {
    var bg= 0;
    $("#changePic").click(function () {
        bg= (bg+1) % 3;
        var name= ["lodge", "lodge1", "lodge2"][bg];
        $("#outerWrapper").css("background-image", "url(images/background-"+name+".jpg)");
    });
});

Upvotes: 1

Amr Elgarhy
Amr Elgarhy

Reputation: 69052

To see what javascript errors are there in chrome, press "ctrl+shift+I" and go to console tab. or "ctrl+shift+J" to go to Console tab directly.

alt text

Upvotes: 0

Stefan H
Stefan H

Reputation: 6683

you are not closing the url for the background

 $("#outerWrapper").css("background-image","url(images/background-lodge.jpg)");
                                                               was missing ^

Upvotes: 6

Related Questions