<section id="toggle-a-class" class="animate-things-wrapper">
    <button id="trigger">Trigger</button>

    <div id="box" class="box">
        Hi there
    </div>
</section>

<script src="../../js/components/toggle-a-class.js"></script>
<section id="toggle-a-class" class="animate-things-wrapper">
    <button id="trigger">Trigger</button>

    <div id="box" class="box">
        Hi there
    </div>
</section>

<script src="{{ path '/js/components/toggle-a-class.js' }}"></script>
/* No context defined. */
  • Content:
    (function () {
      document.addEventListener('DOMContentLoaded', function () {
        console.log("toggle-a-class active");
    
        const button = document.querySelector('#trigger');
        const box = document.querySelector('#box');
    
        button.addEventListener('click', function() {
          box.classList.toggle('active');
        })
      });
    })();
    
  • URL: /components/raw/toggle-a-class/toggle-a-class.js
  • Filesystem Path: components/01-basic/02-toggle-a-class/toggle-a-class.js
  • Size: 331 Bytes
  • Handle: @toggle-a-class
  • Preview:
  • Filesystem Path: components/01-basic/02-toggle-a-class/toggle-a-class.hbs

No notes defined.