$(".code").each(function() { var a = $(this), b = "#jqvmap1_" + a.attr("code"); a.on({ mouseenter: function() { $(b).mouseenter() }, mouseleave: function() { $(b).mouseleave() } }) });