0

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);
}
0

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

Comments

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

in the click event: state = stateReset

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.