title: Javascript - Uncaught TypeError: Cannot read property 'classList' of null
body: <p>How do I check if the element I am clicking on has a classlist? </p>
  
  <pre><code>let dropdown  = target.nextElementSibling.classList.contains('form__select-dropdown')
  </code></pre>
  
  <p>My code is erroring on this line when the element that I click on doesn't have a class attached to it. </p>
  
  <p>Which makes complete sense. </p>
  
  <p>However I only want the below code to run if the nextElementSibling has the class form__select-dropdown:</p>
  
  <pre><code>        if (!selectTag &amp;&amp; dropdown) {
              target.querySelector('.form__select-dropdown').classList.remove('active')
          } else {
              target.nextElementSibling.classList.toggle('active')
          }
  </code></pre>
  
  <p>So I need to check if the target.nextElementSibling.classList exists before I do my condition to avoid the error but I'm unsure how to do this?</p>