title: Bootstrap Scrollspy randomly adds and remove "active" class to navbar links when scrolling if modal is linked to in a navbar link
body: <p><em>EDIT</em></p>
  
  <p>I created my own fix to this using the following code. It uses offset to get the position of the anchor tag, and adds the active class to the nav list item when it reaches that scrollpoint. Works well and is efficient:</p>
  
  <pre><code>customScrollSpy($(window).scrollTop());
  
  $(window).on('scroll', function() {
     var st = $(this).scrollTop();
  
     customScrollSpy(st);
  });
  
  function customScrollSpy(st) {
    if ((st &gt;= $("#top").offset().top &amp;&amp; st &lt; $("#latest-work").offset().top) &amp;&amp; !$("#nav-item-1").hasClass("active"))
     {
        $('[id^="nav-item-"]').removeClass("active");
        $("#nav-item-1").addClass("active");
     }
     else if ((st &gt;= $("#latest-work").offset().top &amp;&amp; st &lt; $("#content1").offset().top) &amp;&amp; !$("#nav-item-2").hasClass("active"))
     {
        $('[id^="nav-item-"]').removeClass("active");
        $("#nav-item-2").addClass("active");
     }
     else if ((st &gt;= $("#content1").offset().top &amp;&amp; st &lt; $("#latest-news").offset().top) &amp;&amp; !$("#nav-item-3").hasClass("active"))
     {
        $('[id^="nav-item-"]').removeClass("active");
        $("#nav-item-3").addClass("active");
     }
     else if (st &gt;= $("#latest-news").offset().top &amp;&amp; !$("#nav-item-4").hasClass("active"))
     {
        $('[id^="nav-item-"]').removeClass("active");
        $("#nav-item-4").addClass("active");
     }
  };
  </code></pre>
  
  <p><em>END EDIT</em></p>
  
  <p>As the title suggests, I have Scrollspy (using Bootstrap obviously), and I initialize it in Javascript with:</p>
  
  <p><code>$('#navbar').scrollspy();</code></p>
  
  <p>Which works fine. However, if one of the list elements (li tag) in the navbar references a div that is a modal, it flips out. When I start scrolling, it flips the active class from that list item to whatever the correct list item at that scroll position should be, so the navbar list items look like they're flickering constantly as you scroll up and down. Here is my navbar and the beginning of my body:</p>
  
  <pre><code>&lt;body id="top" data-spy="scroll" data-target=".navbar"&gt;
  
      &lt;div class="navbar navbar-inverse navbar-fixed-top"&gt;
        &lt;div class="navbar-inner"&gt;
          &lt;div class="container"&gt;
            &lt;a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"&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;/a&gt;
            &lt;a class="brand" href="index.html"&gt;&lt;img src="img/logo.png" alt="logo"&gt;&lt;/a&gt;
            &lt;div class="nav-collapse collapse"&gt;
              &lt;ul class="nav pull-right"&gt;
                &lt;li&gt;&lt;a class="scroll" href="#top"&gt;Home&lt;/a&gt;&lt;/li&gt;
                &lt;li&gt;&lt;a class="scroll" href="#latest-work"&gt;Work&lt;/a&gt;&lt;/li&gt;
                &lt;li&gt;&lt;a class="scroll" href="#content1"&gt;About&lt;/a&gt;&lt;/li&gt;
                &lt;li&gt;&lt;a class="scroll" href="#latest-news"&gt;News&lt;/a&gt;&lt;/li&gt;
                &lt;li&gt;&lt;a class="scroll" data-toggle="modal" href="#request-quote"&gt;Contact&lt;/a&gt;&lt;/li&gt;
              &lt;/ul&gt;
            &lt;/div&gt;&lt;!--/.nav-collapse --&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>As you can see, the last list item ("Contact"), is what is breaking it. Removing the "scroll" class doesn't help any. I'm not sure what the problem is, but changing the href on that list item fixes this whole issue. Also, I have a button in the carousel below the navbar and it opens the modal as well. It doesn't seem to cause this issue--aka this works fine if I change the href of the Contact li but leave the button pointing to the same modal that Contact is pointing to in the above code.</p>
  
  <p>Here is the modal in case that matters:</p>
  
  <pre><code>&lt;!--Request Quote modal--&gt;
      &lt;div id="request-quote" class="modal hide fade" tabindex="-1" data-width="760"&gt;
        &lt;div class="modal-header"&gt;
          &lt;button type="button" class="close" data-dismiss="modal" aria-hidden="true"&gt;×&lt;/button&gt;
          &lt;h3&gt;Request a quote&lt;/h3&gt;
        &lt;/div&gt;
        &lt;form method="POST" action="contact-form-submission.php" class="form-horizontal"&gt;
        &lt;div class="modal-body"&gt; 
          &lt;div class="row-fluid"&gt;
            &lt;div class="span12"&gt;
              &lt;h4&gt;*All information is required&lt;/h4&gt;
              &lt;p&gt;&lt;label&gt;Full Name&lt;/label&gt;
              &lt;input name="name" type="text" class="span12"&gt;&lt;/p&gt;
              &lt;p&gt;&lt;label&gt;Band Name&lt;/label&gt;
              &lt;input name="band_name" type="text" class="span12"&gt;&lt;/p&gt;
              &lt;p&gt;&lt;label&gt;Email&lt;/label&gt;
              &lt;input name="email" type="email" class="span12"&gt;&lt;/p&gt;
              &lt;p&gt;&lt;label&gt;Link to Your Band's Prior Material (Facebook, Youtube, etc.)&lt;/label&gt;
              &lt;input name="link" type="text" class="span12"&gt;&lt;/p&gt;
            &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="row-fluid"&gt;
            &lt;h5 class="span12"&gt;What are you looking for?&lt;/h5&gt;
          &lt;/div&gt;
          &lt;div class="row-fluid"&gt;
            &lt;div class="span4"&gt;
              &lt;p&gt;&lt;label&gt;Select all that apply:&lt;/label&gt;&lt;/p&gt;
              &lt;p class="form-boxes"&gt;&lt;label class="hand"&gt;
              &lt;input name="tracking" type="checkbox" value="tracking"&gt; Tracking
              &lt;/label&gt;
              &lt;label class="hand"&gt;
              &lt;input name="mixing" type="checkbox" value="mixing"&gt; Mixing
              &lt;/label&gt;
              &lt;label class="hand"&gt;
              &lt;input name="mastering" type="checkbox" value="mastering"&gt; Mastering
              &lt;/label&gt;
              &lt;label class="hand"&gt;
              &lt;input name="editing" type="checkbox" value="editing"&gt; Editing
              &lt;/label&gt;
              &lt;label class="hand"&gt;
              &lt;input name="other" type="checkbox" value="other"&gt; Other
              &lt;/label&gt;&lt;/p&gt;
            &lt;/div&gt;
            &lt;div class="span8"&gt;
              &lt;p&gt;&lt;label&gt;Number of Songs&lt;/label&gt;
              &lt;input name="songs" type="text" class="span12"&gt;&lt;/p&gt;
              &lt;p&gt;&lt;label&gt;Explain your project/needs (if you selected "other", please clarify)&lt;/label&gt;
              &lt;textarea name="comments" class="span12"&gt;&lt;/textarea&gt;&lt;/p&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class="modal-footer"&gt;
          &lt;button type="button" data-dismiss="modal" class="btn btn-inverse"&gt;Close&lt;/button&gt;
          &lt;button type="submit" class="btn btn-primary"&gt;Send&lt;/button&gt;
        &lt;/div&gt;
        &lt;/form&gt;
      &lt;/div&gt;
      &lt;!--/Request Quote modal--&gt;
  </code></pre>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I commented out <code>$('#navbar').scrollspy();</code> and it is still happening. Removing my modal's code works, so I'm not sure what the problem is... the modal functions fine except for this. Any ideas what's happening?</p>