javascript - Function to simplify code in jquery -
i have following code working:
$(document).ready(function () { $(".b0").hover(function () { var src = $(this).attr('data'); var href = $(this).attr('href'); $("#imagen").attr('src', src); $("#vinculo").attr('href', href); }); $(".b1").hover(function () { var src = $(this).attr('data'); var href = $(this).attr('href'); $("#imagen").attr('src', src); $("#vinculo").attr('href', href); }); })
but can't simplify function. tried several times , ways...
you can use this:
$(document).ready(function () { $(".b0 , .b1").hover(function () { $("#imagen").attr('src', $(this).attr('data')); $("#vinculo").attr('href', $(this).attr('href')); }); })
Comments
Post a Comment