0
I have until now this code :
document.getElementById('collapseOne').on('click', function(event){
event.preventDefault();
collapseItem(event);
});
but I have more than 1 Collapse (in total four only modifying the numbering at the end of id) And I’d like the code to be just that. I thought of creating a Function to read the id clicked inside the father div where the Collapse meet but unsuccessfully
function clickCollapse(){
var el = document.getElementById('accordionExample');
el.addEventListener('click', function(e) {
var idCollapse = "'" + (e.target.id) + "'";
});
}
so having to just replace this part of the code
document.getElementById('collapseOne');
by the id captured in this last example block:
document.getElementById('idCollapse');
but it didn’t work
Try to take the variable idCollapse without string concatenation, just e.target.id, and at the time of picking it up in Document.getElementById(idCollapse); do it without the quotes
– David Alves
If you use a class, and use the
$(this)
jQuery, to catch the attr id may work. Post the structure of your collapse also that helps.– Gnomo Escalate