title: Bootstrap Navbar Collapse not closing on Click
body: <p>I'm using Bootstrap an it's collapsed Navbar on a one-page website together with a simple scrolling script, so if I click on a single link the page scrolls down to anchor - works great. However the Navbar does not collapse when I click on a link which covers a lot of content on mobile devices - you first have to click on the toggle which is annoying. I found out that it should help to add the data-toggle and data-target attributes to the links, but it doesn't work at all - where is my mistake?</p>
  
  <p>NAVIGATION: </p>
  
  <pre><code>&lt;nav class="navbar navbar-default mainbar" role="navigation"&gt;
      &lt;div class="navbar-header"&gt;
          &lt;button type="button" class="navbar-toggle hvr-bounce-to-bottom" data- toggle="collapse" data-target=".navbar-collapse"&gt;
            &lt;span class="sr-only"&gt;Toggle navigation&lt;/span&gt;
            &lt;span class="icon-bar"&gt;&lt;/span&gt;
            &lt;span class="icon-bar"&gt;&lt;/span&gt;
            &lt;span class="icon-bar"&gt;&lt;/span&gt;
          &lt;/button&gt;
      &lt;/div&gt;
  
      &lt;div class="collapse navbar-collapse navbar-collapse"&gt;
        &lt;ul class="nav navbar-nav"&gt;
           &lt;li&gt;&lt;a data-toggle="collapse" data-target=".navbar-collapse" href="#link1" class="navelement"&gt;Link 1&lt;/a&gt;&lt;/li&gt;
  
           &lt;li&gt;&lt;a data-toggle="collapse" data-target=".navbar-collapse" href="#link2" class="navelement"&gt;Link 2&lt;/a&gt;&lt;/li&gt;
  
         &lt;/ul&gt;
       &lt;/div&gt;
  &lt;/nav&gt;
  </code></pre>
  
  <p>UPDATE:
  It's a Javascript problem. My smooth-scroll script causes an issue: </p>
  
  <pre><code>  var corp = $("html, body");
    $(".navelement").click(function() {
      var flag = $.attr(this, "href");
      corp.animate({
          scrollTop: $(schild).offset().top - 60
      }, 1600, function() {
          window.location.hash = flag;
      });
      return false;
  });
  </code></pre>
  
  <p>It's a pretty simple script, but I have no clue what to do with it to make the navbar collapse.</p>