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 clicking the 3rd or 5th question.
Example: link
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've done some more tests and it's really just getting index 0, so it's opening \ closing only the first content div.
Does .index()
not take the order of elements within the entire file, regardless of location?