CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript frameworks (http://www.codingforums.com/forumdisplay.php?f=62)
-   -   JQuery and scrollTop (http://www.codingforums.com/showthread.php?t=156711)

StealthRT 01-21-2009 04:34 AM

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

rangana 01-21-2009 04:45 AM

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.

StealthRT 01-21-2009 04:47 AM

Well that was an easy fix, Ramgana! Thanks for the help bud! :)

David


All times are GMT +1. The time now is 02:04 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.