"Mehr lesen" Accordion in Vanilla Javascript

Vanilla Javascript für "Mehr lesen" als verstecktes Div.
 

( function() {

    const items = document.querySelectorAll('.readmore-wrapper');

    for (const item of items) {

        const button = item.querySelector('.readmore-block-button');
        const icon = item.querySelector('.readmore-icon');
        const body = item.querySelector('.readmore-hidden');

        body.classList.add('d-none');

        button.addEventListener('click', (e) => {

            e.stopPropagation();

            // Beispiel: Bootstrap Klasse für display: none
            body.classList.toggle('d-none');
           // Icon Styles
            icon.classList.toggle('readmore-icon-open');

        });

    }

} )();

 

Tags