You can check out the livequery plugin here which addresses this
issue:
http://docs.jquery.com/Plugins/livequery
or you can rebind the event after the ajax call:
function refreshcontent(){
$.get("mycontent.php", function(data){
$("#container").animate({ opacity: "hide" }, 200);
$("#container").html(data);
$("#container").animate({ opacity: "show" }, 200);
jQuery(".displayer").click(function()
{
jQuery(this).next(".hidlayer").slideToggle(100);
});
});
}
The new nodes that replace the old ones have no event handlers bound
to them.
I hope this helps.
Jeremy
On Nov 27, 3:13 pm, Sala <[email protected]> wrote:
> I can't figure out what's wrong.
>
> The slidetoggle works fine until I refresh the page using Ajax, even
> though the same exact html is outputted by "mycontent.php"
>
> <!--SLIDETOGGLE-->
> <script type="text/javascript">
> jQuery(document).ready(function() {
> jQuery(".displayer").click(function()
> {
> jQuery(this).next(".hidlayer").slideToggle(100);
> });});
>
> </script>
>
> <script type="text/javascript"><!--AJAX-->
> function refreshcontent(){
> $.get("mycontent.php", function(data){
> $("#container").animate({ opacity: "hide" }, 200);
> $("#container").html(data);
> $("#container").animate({ opacity: "show" }, 200);});
> }
>
> </script>
> <!--JQUERY CODE END-->
>
> <!--OUTPUT FROM MYCONTENT.PHP-->
> <div id="container">
> <div class="message_block">
> <div class="<?php echo $class; ?>"><?php echo $cando; ?></div>
> <div class="message_block_text">
> <table class="displayer btn" border="0" width="645">
> <tr>
> <td width="30"><span
> class="icon"><img src="images/arrow.png"
> alt="arrow" width="16" height="14" /></span></td>
> <td width="100"><div
> class="unha_sections aquen"><span
> class="message_info_text">Usuario </span><span
> class="unha_info_data"><?php echo $aquen; ?></span></div></td>
> <td width="300"><div><span
> class="unha_info_data"><?php
> echo $mymessage; ?></span></div></td>
> <td width="66"><div
> class="unha_sections activated"><span
> class="unha_info_text">Enviado: </span><span class="unha_info_data"><?
> php echo $act; ?></span></div></td>
> <td width="34"
> style="text-align:right;"><img src="images/
> envooo.png" width="34" height="23" alt="" /></td>
> </tr>
> </table>
> <div class="hidlayer">
> <?php echo $message; ?>
> <div class="options">Edit</div>
> </div>
> </div>
> </div>
> </div>
> <!--OUTPUT FROM MYCONTENT.PHP END-->