javascript - Hide/Unhide an image using jquery on hover -


i have 3 <a> tags in html , each contain 2 images. grescale images displayed , other ones set none.

i want hide greyscale image when hover mouse on grescale image , display colored one. , when un-hover want colored image hidden again. how can using jquery?

<a class="mylink" href="">     <img src="img/thumbnails/colored-1.jpg" class="color-image"/>     <img src="img/thumbnails/greyscale-1.jpg" class="greyscale-image"/> </a>  <a class="mylink" href="">     <img src="img/thumbnails/colored-2.jpg" class="color-image"/>     <img src="img/thumbnails/greyscale-2.jpg" class="greyscale-image"/> </a>  <a class="mylink" href="">     <img src="img/thumbnails/colored-3.jpg" class="color-image"/>     <img src="img/thumbnails/greyscale-3.jpg" class="greyscale-image"/> </a>  .color-image {     display:none } 

why use jquery , not pure css?

you can use :hover , toggle display of images.

a.mylink:hover .color-image, a.mylink .greyscale-image {    display: inline; }  a.mylink .color-image, a.mylink:hover .greyscale-image {    display: none; } 

in jquery just

function swap(evt) {     var isover = evt.type === "mouseenter";     link.find(".color-image").toggle(isover);     link.find(".greyscale-image").toggle(!isover); }  $("a.mylink").hover(swap, swap); 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -