Point element A, show / hide element B

I have a <div> element containing an image. Inside this div, I have a <p> element that contains some image information. I want to hover a <div> containing the image, and then show or hide the <p> element.

 <div class="box"> <img src="img/an_039_AN_diskette.jpg" width="310px" height="465px" /> 6 Pharma IT <p class="hoverbox">some information</p> </div> 

Is there an easy way to do this in jQuery?

+4
source share
4 answers
  $("css_selector_of_img").hover( function () { $("css_selector_of_p_element").show(); }, function () { $("css_selector_of_p_element").hide(); } ); 

See http://docs.jquery.com/Events/hover

+6
source

The following will fit all your images and aim at their first sibling with the P tag.

 <script type="text/javascript"> $(document).ready(function(){ $("div.box img").hover( function(){$(this).siblings("p:first").show();}, function(){$(this).siblings("p:first").hide();} ); }); </script> <div class="box"> <img src="somefile.jpg" /> <p>This text will toggle.</p> </div> 
+6
source
 $('#divwithimage').hover( function(){$('#ptag').show();}, //shows when hovering over function(){$('#ptag').hide();} //Hides when hovering finished ); 
+3
source
 <div class="box"> <img ... /> <p class="hoverbox">Some text</p> </div> <script type="text/javascript"> $('div.box img').hover( function() { $('div.box p.hoverbox').show(); }, function() { $('div.box p.hoverbox').hide(); } ); </script> 
+1
source

All Articles