How to scroll HTML page to given anchor using jQuery or Javascript?

Function scrollTo(hash) { location. Hash = "#" + hash; } No jQuery required at all!

I tried this and decided to use this. You were also the first and had shortest code. – Juha Syrjälä Jul 2 '10 at 6:38.

You can use jQuerys .animate(), .offset() and scrollTop. Like $(document. Body).

Animate({ 'scrollTop': $('#anchorName2').offset(). Top }, 2000); example link: jsbin.com/unasi3/edit If you don't want to animate use .scrollTop() like $(document. Body).

ScrollTop($('#anchorName2').offset(). Top); or javascripts native location. Hash like location.

Hash = '#' + anchorid.

As far as creating a selector to find the or an , use $('#'+hash+',aname='+hash+'') or slightly optimized $(document. GetElementById(hash) || 'aname='+hash+'') which will search for the element by id first, and resort to searching the a's only if one isn't found. – gnarf Jul 2 '10 at 7:36.

Something as easy as should do the trick. Function jumpToAnchor(anchor){ location. Href = location.

Href+"#"+ anchor; } Another option would be to use the jQuery ScrollTo plugin.

I tried this and it works also. – Juha Syrjälä Jul 2 '10 at 6:39 @Juha glad it worked as well. :) – ahsteele Jul 2 '10 at 6:53.

Way simpler: element_to_scroll_to = document. GetElementById('anchorName2'); element_to_scroll_to.scrollIntoView().

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions


Thank You!
send