views:

36

answers:

3
A: 

Set up handlers for "mouseover" and "mouseout" on the <input> tags that show only the <p> with matching class.

$('form input').mouseover(function() {
  $('div.description p').hide();
  $('div.description p.' + this.className).show();
}).mouseout(function() {
  $('div.description p').hide();
});

(Not tested, but it's probably close.)

Pointy
...somehow I always forget the inbuilt `className` and go with `...attr('class')` *sigh* =/
David Thomas
+1  A: 
$(document).ready(
  function() {

    $('div.description p').hide();
          $('input').hover(
        function() {
            var matchingExplanationClass = $(this).attr('class');
            $('p.'+matchingExplanationClass).toggle();
        }
    );
  }
  );

Demo at jsbin: http://jsbin.com/ecosu3/2

David Thomas
Perfect! Many thanks. :)
Nimbuz
Just one thing, what if the hovered element is not fixed, lets say it can be input or select or checkbox?
Nimbuz
+1  A: 

Fade in and out, or other effect you need, use .show() and .hide() for a simple no effects presentation.

   var thisClass; 
     $('input').hover(
          function () {
            thisClass = $(this).attr('class');
            $('description.'+thisClass).fadeIn(100)
          }, 
          function () {
            $('description.'+thisClass).fadeOut(100);
          }
        );
Mark Schultheiss