I have a menu with PNG icons. I want when user hover menu item, PNG icon change to GIF icon. i tried this: jsFiddle
$("#image").mouseenter(function(){
// I can set GIF url here
$(this).attr("src","http://jsfiddle.net/img/logo.png");
});
$("#image").mouseleave(function(){
$(this).attr("src","http://jsfiddle.net/img/logo-white.png");
});
but I know this is not right way. I can not do this for every menu item. this is my HTML:
<ul>
<li>
<a> item 1
<img src="image-path" />
</a>
</li>
<li>
<a> item 2
<img src="image-path" />
</a>
</li>
</ul>
I followed this question but this is not what I want. I want to split on last .
or last /
in path.
this code split string on every /
character:
var data =$("#image").attr("src");
var array = data.split('/');
Question:
I have this image path: ../images/icon1.png
and I want to change it to these paths:
../images/icon1.gif
or ../images/hover/icon1.gif