petersvegrup
8/3/2018 - 6:02 AM

Single: Toggle a class on element A when click element B

<script>
    var toggleElement = document.getElementsByClassName('js-toggle-element')[0];
    
    toggleElement.addEventListener('click', function() {
        document.getElementsByClassName('className')[0].classList.toggle('className--active');
    });
    
    // toggleElement.addEventListener('click', function(event) {
    //    document.getElementsByClassName('className')[0].classList.toggle('className--active');
    //    event.preventDefault();
    //}
</script>
<a class="button js-toggle-element" href="javascript:void(0)">
    <span>Click Me</span>
</a>