0

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
  • 1
    href="#" links to the top of the page, so naturally, it scrolls the page all the way up. However, returning false from the onclick handler should prevent the browser from actually following the link. Maybe post some code? Commented Sep 8, 2010 at 10:42

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

2 Comments

i did not know WHERE to put return false; have try something... did not work
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.