scroll to anchor only on data-anchor links

scroll to anchor only on data-anchor links

 html
  1. <a name="anchor-0"></a>
  2. <a data-anchor="anchor-0" class="flex-item-1" href="#target-1">1</a>
  3. <a data-anchor="anchor-0" class="flex-item-1" href="#target-2">2</a>

jquery
  1. $(document).ready(function() {
  2.     function scrollToAnchor(e){
  3.         var aTag = $("a[name='anchor-0']");
  4.         $('html,body').animate({scrollTop: aTag.offset().top},'400');
  5.         e.preventDefault();
  6.     }
  7.     $("a").data('anchor','anchor-0').click(function() {
  8.         scrollToAnchor();
  9.         return false; 
  10.     });            
  11. });
but if if I click on any link in the page where   name="anchor-0"  the function  scrollToAnchor  is called
it must be called only on  data-anchor="anchor-0" links

what is wrong in my function ?
thank you