How you are making use of the library jQuery does not need to create a function. If it is more than one question, I recommend to div
within the tag a
:
<a href="#" class="pergunta">
<li>Como comprar passagem?</li>
<div class="resposta">Apareça por favor</div>
</a>
Already in the code Javascript
$(document).ready(function() {
$('.pergunta').on('click', function() {
$(this).find(".resposta").toggle();
});
});
By clicking on an element that has the attribute class
defined as pergunta
will display or hide the div
response that is within the element.
Example:
$(document).ready(function() {
$('.pergunta').click(function() {
$(this).find(".resposta").toggle();
});
});
.pergunta {
text-decoration: none;
}
.pergunta li {
list-style: none;
margin-bottom: 14px;
}
.resposta {
display: none;
margin-bottom: 14px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="#" class="pergunta">
<li>Como comprar passagem?</li>
<div class="resposta">Apareça por favor</div>
</a>
<a href="#" class="pergunta">
<li>Como comprar passagem?</li>
<div class="resposta">Apareça por favor</div>
</a>
You want to click on:
<a href="#" onclick="Resposta()">
appear<div class="resposta_duvida">
?– NoobSaibot
That’s right, you can help me?
– Bruna
The HTML structure is only that item or there are more questions ?
– NoobSaibot
yes, thank you very much worked perfectly, would you please explain to me
– Bruna
my answer helped?
– romulo henrique
Yes, I’d like you to explain
– Bruna
Bruna da para resolver isso só com CSS e usando checkbox para mostrar e esconder a div, nem precisa de JS, se quer eu faço um modelo de exemplo para vc é bem simples até
– hugocsl