title: jQuery preventDefault in a function
body: <p>I have used <code>preventDefault</code> on an element event like this:</p>
  
  <pre><code>$('#element').click(function (e) {
      do stuff...
  });
  </code></pre>
  
  <p>Now, I have a function that takes an argument already in which I would like to use <code>preventDefault</code> but I'm not sure how:</p>
  
  <pre><code>&lt;a href="#services" id="services_link" class="services" onclick="sectionScroll('services')"&gt;Services&lt;/a&gt;
  
  
  function sectionScroll(id) {
      history.pushState(null, null, '#' + id);
      $('html, body').animate({
          scrollTop: $("#" + id).offset().top
      }, 1000);
  }
  </code></pre>
  
  <p>I tried using return false instead but this caused some flickering when the link was clicked.</p>
  
  <p>How can I add <code>preventDefault</code> to the above function?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>My original question was around using preventDefault in a function that has other arguments.  I didn't need to use inline javascript in the end (it was looking like there was no way to avoid it), so this is what I used.  I think it's quite tidy:</p>
  
  <pre><code>&lt;a href="#services" class="menu-link"&gt;Services&lt;/a&gt;
  
  
     $('.menu-link').click(function (e) {
          e.preventDefault();
          var location = $(this).attr('href');
          history.pushState(null, null, location)
          $('html, body').animate({
              scrollTop: $(location).offset().top
          }, 1000);
      });
  </code></pre>