J'utilise ajax pour insérer une série de blocs d'information via une boucle. Les blocs ont chacun un titre et une longue description qui est cachée par défaut. Ils fonctionnent comme un accordéon, montrant seulement une description à la fois parmi tous les blocs.manipuler le contenu inséré par ajax, sans utiliser le rappel
Le problème est l'ouverture de la description sur le premier bloc. Je voudrais vraiment le faire avec javascript juste après la boucle qui les crée est fait. Est-il possible de manipuler éléments créés à partir d'un appel ajax sans utiliser le rappel?
<!-- example code-->
<style>
.placeholder, .long_description{
display:none;}
</style>
</head><body>
<script> /* yes, this script is in the body, dont know if it matters */
$(document).ready(function() {
$(".placeholder").each(function(){ // Use the divs to get the blocks
var blockname = $(this).html(); // the contents if the div is the ID for the ajax POST
$.post("/service_app/dyn_block",'form='+blockname, function(data){
var divname = '#div_' + blockname;
$(divname).after(data);
$(this).setupAccrdFnctly(); //not the actual code
});
});
/* THIS LINE IS THE PROBLEM LINE, is it possible to reference the code ajax inserted */
/* Display the long description in the first dyn_block */
$(".dyn_block").first().find(".long_description").addClass('active').slideDown('fast');
});
</script>
<!-- These lines are generated by PHP -->
<!-- It is POSSIBLE to display the dyn_blocks -->
<!-- here but I would really rather not -->
<div id="div_servicetype" class="placeholder">servicetype</div>
<div id="div_custtype" class="placeholder">custtype</div>
<div id="div_custinfo" class="placeholder">custinfo</div>
<div id="div_businfo" class="placeholder">businfo</div>
</body>
Vous devez utiliser la fonction de rappel ... c'est ap exemple de pourquoi il est là :) –