Reply to comment

One more thing...

If you wanted to bookmark that anchor for future reference you can't unless JS is turned off. Might I suggest a change to allow for an append to the URL with the proper anchor in order to enable proper bookmarking:

http://www.example.com/article.html

- to -

http://www.example.com/article.html#anchor

First, change all of the question DIVs back to anchor tags and use spans and styles to generate the same look of the headers and paragraphs (set the anchors to display:block). In fact it probably better if you're making a list of questions to use an ordered list here. This way you can use the traditional internal anchors (#a1,#a2,etc.).

Second, no all you need to do to get the proper element to scrollTo is use:

var an = $(this).attr("href");

Third, drop all of the return false and onclick attributes, they're not needed. Replace this functionality by adding the event to the following line:

...
$("#questions > li").click(function(e) {
...

NOTE: the "e" as the function parameter.

Finally, to stop that back and forth you noted, in the onAfter event for scrollTo add the following line:

e.preventDefault();

That will stop the link from jumping, and the best part is the anchor will be properly appended to the URL to allow for proper bookmarking.

Reply

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
2 + 7 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.