title: Cannot read properties of undefined (reading 'display')
body: <p>I'm trying to toggle text showing when I click a button for each item I have in a Carousel.</p>
  <p>When I use &quot;getElementByID&quot; it works fine, but I need to use &quot;getElementsByClassName&quot; because it's a repeater field in the backend and there are several buttons in the whole carousel.</p>
  <p>Anyway here is my code -</p>
  <pre><code> function toggleText(){
    var x = document.getElementsByClassName(&quot;figure-caption-test&quot;);
    if (x.style.display === &quot;none&quot;) {
      x.style.display = &quot;block&quot;;
    } else {
      x.style.display = &quot;none&quot;;
    }
  }
  
  &lt;button class=&quot;figure-button&quot; id=&quot;figure-button&quot; onclick=&quot;toggleText()&quot;&gt;
  REVEAL ANSWER
  &lt;/button&gt;
  
  &lt;figcaption class=&quot;figure-caption-test&quot; id=&quot;reveal-text&quot; style=&quot;display: none;&quot;&gt;
  Text that appears
  &lt;/figcaption&gt;
  </code></pre>
  <p>And the error i'm getting is -
  Cannot read properties of undefined (reading 'display')</p>
  <p>Any help is greatly appreciated, thanks</p>