Reset variable in javascrtp (jQuery)
- by superUntitled
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);
}