title: How to select all elements with a class in JS
body: <p>I'd like to modify all classes with JS.
  Is there way to select them without manually setting the array index (for example [0] or [1] or [184])?</p>
  <p>Example code:</p>
  <pre class="lang-html prettyprint-override"><code>&lt;div class='message'&gt;something:&lt;/div&gt;
  &lt;div class='message'&gt;something&lt;/div&gt;
  </code></pre>
  <pre class="lang-js prettyprint-override"><code>const element = document.querySelectorAll(&quot;.message&quot;);
  element.classList.add(&quot;color&quot;);
  </code></pre>
  <p>It works only when I add <code>[0]</code> and only for the first element that has the class.
  But I'd like to modify all the elements with the class.</p>