Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-21-2009, 04:34 AM   PM User | #1
StealthRT
Regular Coder

 
StealthRT's Avatar
 
Join Date: Aug 2006
Posts: 175
Thanks: 13
Thanked 0 Times in 0 Posts
StealthRT can only hope to improve
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
StealthRT is offline   Reply With Quote
Old 01-21-2009, 04:45 AM   PM User | #2
rangana
Senior Coder

 
rangana's Avatar
 
Join Date: Feb 2008
Location: Cebu City, Philippines
Posts: 1,752
Thanks: 65
Thanked 372 Times in 365 Posts
rangana will become famous soon enoughrangana will become famous soon enough
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
rangana is offline   Reply With Quote
Users who have thanked rangana for this post:
StealthRT (01-21-2009)
Old 01-21-2009, 04:47 AM   PM User | #3
StealthRT
Regular Coder

 
StealthRT's Avatar
 
Join Date: Aug 2006
Posts: 175
Thanks: 13
Thanked 0 Times in 0 Posts
StealthRT can only hope to improve
Well that was an easy fix, Ramgana! Thanks for the help bud!

David
StealthRT is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


Advertisement
Log in to turn off these ads.