Вопрос

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)
    }
);
Это было полезно?

Решение

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)
    }
);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top