So I've been messing around with symfony as of late, and right now I can generate these cards which contain our FAQ questions and answers, my question is: How can I add a collapse function to those generated cards?
I was thinking about doing a accordion collapse, however I can't find a whole lot on internet that worked for me. so if anyone can give me some tips on how I could possibly add a collapse to these generated cards.
I think this should be all the code I really need to include, but if you need anything else let me know
Any help would be really appreciated!
{% extends 'base.html.twig' %}
{% block scripts %}
{{ parent() }}
<script>
var counter = 0;
const content = document.getElementById('content');
$(document).ready(function() {
$.ajax({
url: "http://127.0.0.1:8000/api/faq"
}).then(function(data) {
data.forEach(FAQ => {
counter++;
const card = document.createElement('div');
card.setAttribute('class','card');
const question = document.createElement('h3');
question.setAttribute('id','question'+counter);
const answer = document.createElement('p');
answer.setAttribute('id', 'answer'+counter);
content.appendChild(card).className = "FAQCard";
card.appendChild(question);
card.appendChild(answer);
$('#question'+counter).append(FAQ.question );
$('#answer'+counter).append(FAQ.answer );
})
});
});
</script>
{% endblock %}
{% block title %}
Ervaringsmanager
{% endblock %}
{% block content %}
{% endblock %}