$('.social').mouseover(function(){ var img = $('img',this).attr('src'); img = img.split('/'); ruta = img[img.length-2] img = img[img.length-1]; img = ruta+"/"+img.split('.')[0]; img+='_hover.png'; $('img',this).attr('src',img) }); $('.social').mouseout(function(){ var img = $('img',this).attr('src'); img = img.split('/'); ruta = img[img.length-2] img = img[img.length-1]; img = ruta+"/"+img.split('_')[0]; img+='.png'; $('img',this).attr('src',img) });