0

I have a menu where i basically click and hide current p and fadein the corresponding button text. Thing is, it makes my page literally jump to the top.

Here is the html for menu:

<li class="sub"><a href="#" class="sub_ha1"> 
   › Instalação/Configuração de Componentes</a>
</li>

Here is the html for corresponding text

:

<div id="sub_ha1" class="text" style="display:block;">
  <img src="../images/serv/ha1.jpg" alt="">
  <h1> Instalação/Configuração de Componentes - 35€ </h1>

  <p>Chamamos de hardware a todos os componentes ..... </p>
</div>

Here is the jQuery:

$("#navigation a.sub_ha1").click(function () {
$(".text").hide();
$("#sub_ha1").fadeIn();
return false;
});

What i want, is a way to prevent it because it just makes it annoying after getting through a few menus.

Thanks

EDIT: http://jsfiddle.net/M2AE6/ if you click about or contact menus after clicking 1st or 2nd menu item you'll see what is happening.

Adil Shaikh
  • 44,509
  • 17
  • 89
  • 111
Bruno Charters
  • 454
  • 2
  • 6
  • 14

3 Answers3

1

You can also change your links href.

<a href="javascript:void(0);">text</a>
Jeffpowrs
  • 4,430
  • 4
  • 30
  • 49
0

Although your code seems right, you can try this one:

$("#navigation a").click(function(e){
   e.preventDefault(); // <----stop it here
   $(".text").hide();
   $("#"+this.className).fadeIn(); // <--this will get you the specific div you want to fade In.
   // $("[id='"+this.className + "']").fadeIn();// <---another way to do it
});
Jai
  • 74,255
  • 12
  • 74
  • 103
0

As tcovo said in a comment to the main question what if you use function() { $(".text").not($("#sub_ha1").fadeIn()).hide(); return false; } so that #sub_ha1 gets shown (initially with opacity 0) before the other .text are hidden? – tcovo , this actually worked out pretty great except for when total text height was smaller than menu. Thanks all.

Bruno Charters
  • 454
  • 2
  • 6
  • 14