title: Scrolldown after clicking button javascript
body: <p>For my website, i would like to scrolldown automatically to an article when the user click on a button category.</p>
  <p>Here is my twig code.
  `</p>
  <pre><code>                    {% if category is not null and category|length &gt; 0 %}
                                                                                               
                          {% for categorie in category %}
                              &lt;li class=&quot;nav-item category-link&quot;&gt;
                                  &lt;button class=&quot;nav-link active&quot; categoryId=&quot;{{categorie.id}}&quot;&gt;{{categorie.name}}&lt;/button&gt;
                              &lt;/li&gt;
                          {% endfor %}
                      {% endif %}
                  &lt;/ul&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/nav&gt;
      &lt;div class=&quot;&quot;&gt;
          {% for content in contents %}
              &lt;div contentId=&quot;{{content.id}}&quot;&gt;
                  &lt;h2 class=&quot;text-center&quot;&gt;{{content.title}}&lt;/h2&gt;
              &lt;/div&gt;`
  </code></pre>
  <p>And this is my JS part.</p>
  <pre><code>var contentId = document.querySelector('div').getAttribute('contentId');                       
  var categoryId = document.querySelector(&quot;button&quot;).getAttribute('categoryId');
  if(categoryId){
          categoryId.addEventListener('click', function() {
          if (contentId === categoryId){
              window.scrollTo(contentId);
          }
      });
  }```
  
  For information, actually in my database contentId related to categoryId have the same value. But for future they may not have the same value.
  
  Thanks a lot for your help.
  </code></pre>