7.3. Dynamic FAQ

<style>
    .qfaq {
        cursor: pointer;
    }

    .ansfaq {
        overflow: hidden;
        max-height: 0;
    }
</style>

<script>
    var qfaq = document.getElementsByClassName('qfaq');
    var i;
    var qtot = qfaq.length;
    for (i = 0; i < qtot; i++) {
        qfaq[i].addEventListener('click', function () {
            var ansfaq = this.nextElementSibling;
            if (ansfaq.style.maxHeight) {
                ansfaq.style.maxHeight = null;
            } else {
                ansfaq.style.maxHeight = ansfaq.scrollHeight + 'px'
            }
        })
    }
</script>