---
title: "jquery scroll to anchor"
description: "Werbeagentur Wegberg"
url: "https://www.digital-noises.com/en/jquery-scroll-to-anchor/"
canonical: "https://www.digital-noises.com/en/jquery-scroll-to-anchor/"
type: "WebPage"
date_published: "2011-08-14T12:38:43+02:00"
date_modified: "2012-11-03T12:49:20+02:00"
author: "florian"
locale: "en_US"
---

# jquery scroll to anchor

The following script scrolls on klick on an  tag called “#anchor” to  an  tag with the attribute name=”anchor”.

$("a[href^='#']").click(function() {
   $('html,body').stop().animate({
       scrollTop: $("a[name^='"+$(this).attr("href").substr(1)+"']")
       .offset().top},1500);
      return false;
})
