Home > Article > Web Front-end > How Can I Scroll to a Specific Anchor Using JavaScript?
To navigate a webpage to a particular anchor using JavaScript, follow these steps:
You have HTML tags with specified names or IDs:
<a name="anchorName">...</a>
or
<h1>
To achieve the same navigation effect as visiting http://server.com/path#anchorName:
function scrollTo(hash) { location.hash = "#" + hash; }
No external libraries like jQuery are needed!
The above is the detailed content of How Can I Scroll to a Specific Anchor Using JavaScript?. For more information, please follow other related articles on the PHP Chinese website!