javascript - On hover fadeToggle with multiple divs -


so have divs img inside. above img div hidden, appear on hover of img. know how make work, want simpler, more own learning. want work same have, simpler , cleaner jquery/javascript.

$('#img-1').hover(function(){     $('#overlay-1').stop().fadetoggle(400); }); $('#img-2').hover(function(){   $('#overlay-2').stop().fadetoggle(400); }); 

here in action: jsfiddle

 $('.img').hover(function(){     $(this).find('.overlay').stop().fadetoggle(400);  }); 

the $(this) keyword object you're calling hover() on. find() children of thing hovered class .overlay


Comments

Popular posts from this blog

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

javascript - Confirm a form & display message if form is valid with JQuery -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -