1
So, guys, I have a schematic here like FAQ that the site administrator who registers the Faqs. Each new registered question generates two new Ivs:
<div>Pergunta1</div>
<div>Resposta1</div>
Then I use a Jquery to toggle effect. When the person clicks on the question it displays the answer:
$(function(){
$('#pergunta1').click(function(){
$('#respota1').toggle(700);
});
Only that on the average that the question and answer Divs are added I have to add jQuery manually.
If you register another:
<div>Pergunta2</div>
<div>Resposta2</div>
Then I would have to do another Jquery shown up there changing...
$(function(){
$('#pergunta2').click(function(){
$('#respota2').toggle(700);
});
Could jQuery automate that? Like a while or something?
Can you explain the code that "generates two new Ivs"? It creates Ids in the elements?
– Sergio
What is the element where these Divs are inserted? is the same element for all?
– Sergio
It’s a while in php that pulls from the bank... and a counter that is in the id.. type: <? php $a = 1; while(...){ ? > <div id="question<? php echo $a? >"></div>"; <? php $a++; } };?>
– Jaider Master Info
What is the element where these Divs are inserted? is the same element for all?
– Sergio
They stay inside a box with another div
– Jaider Master Info
Okay, so you can delegate the event, so it’s simple. Can you [Edit] the question with an example HTML with 2 questions, and what do you want to happen when one is clicked? So it will be simple to answer adjusted to your problem.
– Sergio
Actually I need to know how to make jQuery understand that there will always be a new id=question[x] ? Without I need to insert manual, understood ?
– Jaider Master Info
Exactly, so I say it’s simple. But you need to delegate because these elements don’t exist yet when the page loads.
– Sergio
Sorry friend @Sergio I’m new here, but what would delegate?
– Jaider Master Info