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

'hasOwnProperty' in javascript -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -

How to understand 2 main() functions after using uftrace to profile the C++ program? -