Reset variable in javascrtp (jQuery)

Posted by superUntitled on Stack Overflow See other posts from Stack Overflow or by superUntitled
Published on 2010-05-11T20:47:04Z Indexed on 2010/05/11 20:54 UTC
Read the original article Hit count: 290

Filed under:
|

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

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JavaScript