1
Hello, I would like to make a script similar to accordion.
My HTML
<div class="pergunta">
<h3>Titulo</h3>
<article>Texto</article>
</div>
<div class="pergunta">
<h3>Titulo</h3>
<article>Texto</article>
</div>
The idea is that when you click on H3, open the corresponding article. I made my jQuery as follows
var aux = 0;
$(".pergunta").click(function(){
if(aux == 0){
$("article", this).slideDown();
aux++;
}else{
$("article", this).slideUp();
aux--;
}
});
Compile. But if I click anywhere on the div question, it closes again. So I wanted to do something like:
var aux = 0;
$(".pergunta h3").click(function(){
if(aux == 0){
$(this).parent().children('article').slideDown();
aux++;
}else{
$(this).parent().children('article').slideUp();
aux--;
}
});
Don’t compile, I imagine you’re wrong. Just to be clear. How can I do without using Ids? In order to save code.
Strange, because I tested your last code in which you say does not compile, but it works perfectly, as you can see here: https://jsfiddle.net/leandrobeandrade/sz24gcbf/
– LeAndrade