views:

23

answers:

2

I have a javascript (jquery) snippet that is link to a href="#" to toggle the click.. everything is fine exept when i click around the page is going back all scrooled up... i prefer the page to stay where it is... return false done nothing...

here is the code :

<script type="text/javascript"> 
 jQuery(document).ready(function(){
  jQuery('#social li').click(function(){
   button = jQuery(this).attr('class');
   switch (button)
    { 
    case 'social1' : 
    jQuery('#facebookbox').show(); 
    jQuery('#twitterbox').hide();
    jQuery('.social1 a').addClass('selected');
    jQuery('.social2 a').removeClass('selected');
    break;

    case 'social2' : 
    jQuery('#facebookbox').hide(); 
    jQuery('#twitterbox').show(); 
    jQuery('.social2 a').addClass('selected');
    jQuery('.social1 a').removeClass('selected');
    break;
    }
  });
}); 
</script>
+1  A: 

Make it link to a non-existent anchor, like href="#_"

Litso
it work !.... did not know that one
marc-andre menard
A: 

You can set the href as href="javascript:void(0)". That should prevent it from jumping around. Make sure to return false in the onclick event otherwise you may have problems in IE6.

Liggi
i did not know WHERE to put return false; have try something... did not work
marc-andre menard
Your link would look like this: <a href="javascript:void(0)" onclick="Function(); return false;">Hello world</a>.EDIT: Sorry, I've just noticed you are doing it differently. Put "return false" at the end of the anonymous click function. jQuery might actually already handle this for you, I'm not 100% sure.In your example code "return false" would come after your switch statement.
Liggi