Since you are making use of the jQuery library, you do not have to create a function. If it is more of a question, I recommend putting div
inside the a
tag:
<a href="#" class="pergunta">
<li>Como comprar passagem?</li>
<div class="resposta">Apareça por favor</div>
</a>
In the JavaScript tag
$(document).ready(function() {
$('.pergunta').on('click', function() {
$(this).find(".resposta").toggle();
});
});
Clicking on an element that has the attribute class
set to pergunta
will display or hide the div
response that is inside 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><ahref="#" 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>