Reputation: 2112
I need to pass value of current_src
to mouseleave function.
console.log returns undefined
.
var current_src, swap_src;
jQuery(".browseProductImage").hover(
function(){
var current_src = jQuery(this).attr('src');
var swap_src = jQuery(this).next().attr('src');
jQuery(this).attr('src', swap_src);
},
function(){
jQuery(this).attr('src', current_src);
console.log(current_src)
}
);
Upvotes: 0
Views: 731
Reputation: 74420
Remove the second var
for current_src
, you want to use here the upper scoping one variable:
var current_src, swap_src;
jQuery(".browseProductImage").hover(
function(){
current_src = jQuery(this).attr('src');
var swap_src = jQuery(this).next().attr('src');
jQuery(this).attr('src', swap_src);
},
function(){
jQuery(this).attr('src', current_src);
console.log(current_src)
}
);
Upvotes: 1