tags:

views:

297

answers:

2

I want to implement a global anchor type of functionality.

I want to include a link to the main part of the web page, globally by inputting into my header.inc file.

When you select the link, it will scroll to the main part of the page, which is within the div class content-body

<div class="content-body">
  main content
</div>

So it will scroll down to where the div begins.

I want to achieve the anchor tag functionality, but it goes to a div class, not id.

I want to know if there is a way to do this with jQuery. Why I want to do this, is because I can globally implement this throughout the entire existing website.

A: 

Well, traditionally this is done by using an id attribute on an element and making the anchor point to that id.

<a href="#main">Go to Main Element</a>

<div id="main"></div>

The hash tag is the key as that indicates that you're wanting to direct the user to somewhere within the same document.

This is, of course, assuming that you are not saying that the class attached to the 'main' element in question is your only option.

slant
I was looking for a way to do this with jQuery, since it uses div class="content-body" throughout the entire website already.
Brad
Pardon, I noticed the jquery tag after you said that.The only way that I've found to scroll to elements by class would be the ScrollTo plugin (http://plugins.jquery.com/project/ScrollTo).
slant
Looks like all you'd need to do is the following: $('link-to-body-content').click(function(){ $.scrollTo('.content-body'); });
slant
Ouch - pardon the lack of formatting. I didn't realize it would not translate. Hopefully that made sense.
slant
A: 

You could use scrollTop in jQuery. Here is a page that shows this.

Buggabill