views:

79

answers:

2

I am trying to reset a variable (that updates the src value for an image) when an area of an image map is clicked, so that the hover function calls a different image when the user hovers over another area in the image map.

I have a variable called "state" that I set right off the bat. This is the variable that I want to reset when an area is clicked.

var state = "path/to/images/feed1.png";

I have a couple of functions involving hover() and click().

$("#Map area").click(
    function () {
        var button = $(this).attr("id");                
        // here is where i want to reset the 'state' variable
        var state = "path/to/images/" + button + ".png";
        alert("you clicked "+button+" hello");
        return false;
    }
); 


$("#Map area").hover(
    function () {
        var button = $(this).attr("id");
        over("path/to/images/" + button + ".png");
    },
    function () {
        off();
    });

And some functions that these functions call:

function over(image) {
    $("#feednavImg").attr("src", image);
}

function off() {
    $("#feednavImg").attr("src", state);
}
+3  A: 

Remove the var from infront of state were you are trying to 'reset' it. Putting var infront of the variable defines it in the scope of the #Map area click handler.

PetersenDidIt
yes, this is what was wrong. thank you!
superUntitled
A: 
var state = "path/to/images/feed1.png";
var stateReset = state

in the click event: state = stateReset

Diodeus