Hi,

I wrote this code for a simple "hide and show" effect and I am looking
for any advice or examples of how I can refactor the code. I tried
using a hash but it didn't work out right and I am thinking that maybe
I should make a object method.

here is the code:

$(document).ready(function() {
  var $firstPara = $('p.a');
   $firstPara.hide();

  $('a.one').hover(function() {
   $('a.one').fadeOut('slow').fadeIn('slow');

   if ($firstPara.is(':hidden')) {
       $firstPara.fadeIn('slow');
   } else {
      $firstPara.fadeOut('slow');
   }
        return false;
});
});

$(document).ready(function() {
  var $secondPara = $('p.b');
   $secondPara.hide();

  $('a.two').hover(function() {
   $('a.two').fadeOut('slow').fadeIn('slow');

   if ($secondPara.is(':hidden')) {
       $secondPara.fadeIn('slow');
   } else {
      $secondPara.fadeOut('slow');
   }
        return false;
});
});

$(document).ready(function() {
  var $thirdPara = $('p.c');
   $thirdPara.hide();

  $('a.three').hover(function() {
   $('a.three').fadeOut('slow').fadeIn('slow');

   if ($thirdPara.is(':hidden')) {
       $thirdPara.fadeIn('slow');
   } else {
      $thirdPara.fadeOut('slow');
   }
        return false;
});
});

Reply via email to