Reputation: 2255
I have a variable I define as default_gym. In an onclick I change the variable. The problem is when I then reference the variable in the function menu_expand through the hover the variable hasn't change, or rather the div '#newburyport' isn't taking the css.
var default_gym;
$('.intro_circle').on('click', function () {
if ($(this).is("#intro_newburyport")) {
var default_gym = 'newburyport';
}
});
function menu_expand() {
$('#'+default_gym).css({
color:"#ffffff"
});
}
$('#menu-wrapper').hover(
function() {
if ( $('#menu-wrapper').hasClass('safe_hover')) {
menu_expand();
}
},
function() {
if ( $('#menu-wrapper').hasClass('safe_hover')) {
menu_collapse();
}
}
);
Upvotes: 0
Views: 34
Reputation: 54619
You are creating a new variable inside the click function. Remove var
to assign a value to your existing global variable
Upvotes: 1
Reputation: 9348
Remove the "var" within the jQuery method:
$('.intro_circle').on('click', function () {
if ($(this).is("#intro_newburyport")) {
default_gym = 'newburyport';
}
});
Upvotes: 0