Adding ScrollTo effect to links, multiple on the same page, to different locations

I am trying to learn jQuery, so please bare with me. I have a series of links that look like this:

<a class="pagescroll" id="1goto" href="#">link</a>
<a class="pagescroll" id="2goto" href="#">link</a>
<a class="pagescroll" id="3goto" href="#">link</a>

Then I have anchors like these, positioned further down the page:

<a id="dest1"></a>
<a id="dest2"></a>
<a id="dest3"></a>

My thinking is that I can use jQuery to identify this type of link by the class, then take the link's ID to identify where in the page it should scroll to (goto1 scrolls to the ID desc1). I don't know if this is the best/most efficient way to do it, so I'm open to suggestions.

My non-working script looks like this:

<script type="text/javascript">
      $(function(){
            $('.pagescroll').click(function(){
                  var linkId=$(this).attr('id');
                  var linkNum=parseInt(linkId, 10);
                  var linkTo='dest'+linkNum;
                  $scrollTo(linkTo,'slow',{axis:'y'});
            });
      });
</script>

linkTo is populating correctly, if you click the link with 3goto it will populate linkTo with dest3, so I just need to figure out how to get the scrollTo to take that variable and use it to scroll to the element with the ID of linkTo.

Thank you!
Brad BansnerWeb DeveloperAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
chuckaliciousConnect With a Mentor Commented:
Ok I think this is as straight forward as you having missed the "." between $ and scrollTo

Change this line:

$scrollTo(linkTo,'slow',{axis:'y'});

to

$.scrollTo(linkTo,'slow',{axis:'y'});
0
 
chuckaliciousCommented:
I think you need a plugin for scrollTo...

http://demos.flesler.com/jquery/scrollTo/

0
 
Brad BansnerWeb DeveloperAuthor Commented:
I have the plugin loaded. Here is my sample page:

http://secure.bbdesign.com/lighthousechristiancenter/support-groups.asp
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Brad BansnerWeb DeveloperAuthor Commented:
I added that, but still doesn't go anywhere.
0
 
Brad BansnerWeb DeveloperAuthor Commented:
Wait, I found it:

$.scrollTo('#'+linkTo,'slow',{axis:'y'});

You pass the # to identify it as an ID, then it works. Thanks!
0
 
Brad BansnerWeb DeveloperAuthor Commented:
But it did also need the period.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.