Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder StealthRT's Avatar
    Join Date
    Aug 2006
    Posts
    185
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Question JQuery and scrollTop

    Hey all i am trying to figure out what i am doing wrong here with this code. The code below works but it only works for the first link for some reason...
    Code:
    $(document).ready(function() {
      $('#mybutton').click(function() {
        $('html, body').animate({scrollTop: '0px'}, 500);
    	return false;
    
      });
    });
    Code:
    <A href="#" title="page1" id="mybutton"><span class="buttontext" id="mybutton" onMouseOver="this.style.backgroundColor='#000';" onMouseOut="this.style.backgroundColor='#CCC';">1</span></A>
    <A href="#" title="page2" id="mybutton"><span class="buttontext" id="mybutton" onMouseOver="this.style.backgroundColor='#000';" onMouseOut="this.style.backgroundColor='#CCC';">2</span></A>
    It works for the "1" but it only scrolls a tad bit for "2". Any ideas on why this is??

    Thanks,
    David

  • #2
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    ID is unique in every page - this should only exist once in your markup.

    Use class instead, and change the selector from pound sign to dot.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • Users who have thanked rangana for this post:

    StealthRT (01-21-2009)

  • #3
    Regular Coder StealthRT's Avatar
    Join Date
    Aug 2006
    Posts
    185
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Well that was an easy fix, Ramgana! Thanks for the help bud!

    David


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •