title: I need a shortcut for selecting inside links in order to use this function
body: <p>I am new to web development and I am in a little trouble. I am using the following jQuery function in order to scroll the page for specific divs with internal links. </p>
  
  <pre><code>$('a[href^="#"]').on('click', function(event) {
      var target = $( $(this).attr('href') );
      if( target.length ) {
          event.preventDefault();
          $('html, body').animate({
              scrollTop: target.offset().top-30
          }, 1000);
      }
  });
  </code></pre>
  
  <p>The problem is that the function works also on other elements with internal links that should not have the scroll effect (accordion elements). The only way I can prevent this from happening is to write the same function for all the links that I want to apply the function to ("#link1", "#link2", "#link3", "#link4", ... , "#linkn").
  I tried to use an array with the links and to use each value of the array in the function but I don't know how to write the loop.</p>
  
  <p>Can you please help me? </p>