How to scroll HTML page to given anchor

0 votes

I’d like to make the browser to scroll the page to a given anchor, just by using JavaScript.

I have specified a name or id attribute in my HTML code:

 <a name="anchorName">..</a>

or

 <h1 id="anchorName2">..</h1>

I’d like to get the same effect as you’d get by navigating to http://server.com/path#anchorName. The page should be scrolled so that the anchor is near the top of the visible part of the page.

Nov 26, 2020 in JQuery by kartik
• 37,520 points
1,256 views

1 answer to this question.

0 votes

Hello @kartik,

Try this:

function scrollTo(hash) {
    location.hash = "#" + hash;
}

No jQuery required at all!

answered Nov 26, 2020 by Niroj
• 82,880 points

Related Questions In JQuery

0 votes
1 answer

How to Smooth scroll to div id jQuery?

Hello @kartik, You need to animate the html, body $("#button").click(function() ...READ MORE

answered Oct 5, 2020 in JQuery by Niroj
• 82,880 points
36,136 views
0 votes
1 answer

How to set data attributes in HTML elements?

Hello @kartik, HTML <div id="mydiv" data-myval="10"></div> JS var a = $('#mydiv').data('myval'); ...READ MORE

answered Oct 5, 2020 in JQuery by Niroj
• 82,880 points
1,144 views
0 votes
1 answer

How to disable HTML links using jquery?

Hello @kartik, Got the fix in css. td.disabledAnchor a{ ...READ MORE

answered Nov 26, 2020 in JQuery by Niroj
• 82,880 points
2,401 views
0 votes
1 answer

How to Disabling and enabling a html input button?

Hello @kartik, Using jQuery Disabling a html button $('#Button').attr('disabled','disabled'); Enabling a ...READ MORE

answered Nov 26, 2020 in JQuery by Niroj
• 82,880 points
1,294 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,880 points
22,870 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,880 points
2,928 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,880 points
2,863 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,880 points
44,195 views
0 votes
1 answer

How to scroll to element from bottom to top with a nice animation using Jquery?

Hello @kartik, Assuming you have a button with ...READ MORE

answered Sep 10, 2020 in JQuery by Niroj
• 82,880 points
4,179 views
0 votes
1 answer

How to get the size of the screen, current web page and browser window?

Hello @kartik, You can get the size of ...READ MORE

answered Sep 10, 2020 in JQuery by Niroj
• 82,880 points
488 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP