2
I have a jQuery that I made to open and close a div by clicking on the corresponding question. The problem is that only the first div is opening closing, even though I click on the 3rd or 5th question.
Example: http://jsfiddle.net/1sozc3rL/
jQuery:
var SC = jQuery.noConflict();
SC(document).ready(function() {
SC('.FAQ-conteudo').hide();
SC('.FAQ-fecha').hide();
SC('.FAQ-pergunta').removeClass('FAQ-atual');
SC('.FAQ-pergunta').click(function(){
var i = SC(this).index();
var faqTemClasse = SC('.FAQ-pergunta:eq('+i+')').hasClass('FAQ-atual');
if (faqTemClasse) {
SC('.FAQ-pergunta:eq('+i+')').removeClass('FAQ-atual');
SC('.FAQ-conteudo:eq('+i+')').fadeOut(300);
SC('.FAQ-fecha:eq('+i+')').hide();
SC('.FAQ-abre:eq('+i+')').show();
} else {
SC('.FAQ-conteudo').fadeOut(300);
SC('.FAQ-pergunta:eq('+i+')').addClass('FAQ-atual');
SC('.FAQ-conteudo:eq('+i+')').fadeIn(300);
SC('.FAQ-fecha:eq('+i+')').show();
SC('.FAQ-abre:eq('+i+')').hide();
}
});
});
Edit: I did some more tests and really he’s only getting index 0, so he’s only opening closing the first div of content.
The .index()
does not take the order of elements within the entire file, regardless of the place?
As there are several Divs, I think you could show/hide setting Ids on each of them, and not by class as you are doing. You would have more control over the shares of each DIV.
– Franchesco
But I would have to create a jQuery script for every event of every div, right? I wanted something standard :\
– Ricardo
You’re right. I used the Collapse bootstrap.
– Franchesco