title: Bootstrap 4 scrollspy for nav item inside div not working
body: <p>I can't seem to get scrollspy to work. I have a nav item inside a div item that is hidden at times. This nav item needs to have scrollspy working. I'm not sure if the problem is with the active class or something else. When clicking a link it doesn't change to active. Scrolling to the section doesn't work either.</p>
  
  <p>main-page.html </p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;!-- can be dropped but must appear because of bootstrap warning --&gt;
      &lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&gt; 
      &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
      &lt;meta name="description" content=""&gt;
      &lt;meta name="author" content=""&gt;
      &lt;title&gt;My title&lt;/title&gt;
      &lt;link rel="stylesheet" href="styles.css"&gt;
      &lt;!-- Latest compiled and minified CSS --&gt;
      &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css"&gt;
  
      &lt;!-- jQuery library --&gt;
      &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;
  
      &lt;!-- Popper JS --&gt;
      &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"&gt; &lt;/script&gt;
  
      &lt;!-- Latest compiled JavaScript --&gt;
      &lt;script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"&gt;&lt;/script&gt;
      &lt;!-- JavaScript code for this page --&gt;
      &lt;script src="main_page.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;!-- A navbar that is always on top --&gt;
      &lt;nav class="navbar navbar-expand-sm fixed-top"&gt;...&lt;/nav&gt;
  &lt;div class="container-fluid"&gt;
  &lt;!-- Content that shows up when navigating to the site or when the logo is clicked --&gt;
          &lt;div id="landing-page"&gt;...&lt;/div&gt;
  &lt;!-- Shows all the Features of this product --&gt;
          &lt;div id="features-page" hidden=true data-spy="scroll" data-target="features-navbar" data-offset="1"&gt;
              &lt;div class="jumbotron features-jumbotron text-center"&gt;
                  something
              &lt;/div&gt;
              &lt;!-- Navbar in question --&gt;
              &lt;nav class="navbar navbar-expand-sm justify-content-center sticky-top" id="features-navbar"&gt;
                  &lt;div class="gray-border"&gt;
                      &lt;div class="collapse navbar-collapse"&gt;
                          &lt;ul class="navbar-nav  mr-auto"&gt;
                              &lt;li class="nav-item"&gt;
                                  &lt;a class="nav-link nav-button active" href="#lease-feature"&gt;Lease&lt;/a&gt;
                              &lt;/li&gt;
                              &lt;li class="nav-item"&gt;
                                  &lt;a class="nav-link nav-button" href="#finance-feature"&gt;Finances&lt;/a&gt;
                              &lt;/li&gt;
                              &lt;li class="nav-item"&gt;
                                  &lt;a class="nav-link nav-button" href="#organized-feature"&gt;Organized&lt;/a&gt;
                              &lt;/li&gt;
                              &lt;li class="nav-item"&gt;
                                  &lt;a class="nav-link nav-button" href="#community-feature"&gt;Community&lt;/a&gt; 
                              &lt;/li&gt;
                          &lt;/ul&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/nav&gt;
              &lt;div class="feature-item" id="lease-feature"&gt;
                  lease-feature
                  &lt;br/&gt;
                  &lt;br/&gt;
                  &lt;br/&gt;
                  &lt;br/&gt;
                  &lt;br/&gt;
                  lease-feature end
              &lt;/div&gt;
              &lt;div class="feature-item" id="finance-feature"&gt;
                  Finance
                  &lt;br/&gt;
                  &lt;br/&gt;
                  &lt;br/&gt;
                  &lt;br/&gt;
                  &lt;br/&gt;
                  &lt;br/&gt;
                  &lt;br/&gt;
                  Finance end
              &lt;/div&gt;
              &lt;div class="feature-item" id="organized-feature"&gt;
                  organized
                  &lt;br/&gt;
                  &lt;br/&gt;
                  &lt;br/&gt;
                  &lt;br/&gt;
                  &lt;br/&gt;
                  &lt;br/&gt;
                  &lt;br/&gt;
                  &lt;br/&gt;
                  organized end
              &lt;/div&gt;
              &lt;div class="feature-item" id="community-feature"&gt;
                  community-feature
                  &lt;br/&gt;
                  &lt;br/&gt;
                  &lt;br/&gt;
                  &lt;br/&gt;
                  &lt;br/&gt;
                  &lt;br/&gt;
                  &lt;br/&gt;
                  &lt;br/&gt;
                  community-feature end
              &lt;/div&gt;
              end
          &lt;/div&gt;
   &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>styles.css</p>
  
  <pre><code>body { 
      padding-top: 110px;
  }
  
  nav{
      background-color: white;
  }
  .nav-button{
      color: black;
  }
  
  .active{
      border-left: 2px solid black;
  }
  
  .gray-border{
      border-top: .1px solid #d9d9d9;
      border-bottom: .1px solid #d9d9d9;
  }
  
  .feature-item{
      padding-top: 220px;
  }
  
  ...
  </code></pre>