CodeIgniter Forums
lost in jQuery - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: lost in jQuery (/showthread.php?tid=15005)



lost in jQuery - El Forum - 01-23-2009

[eluser]zovar[/eluser]
When using jQuery I always have one problem. I assume that it's a common thing.

Let's say that my document structure is as follows:
Code:
<div id="content">
  <a href="/blog" class="toggleContent">toggle</a>
  <p>some text</p>
</div>

then in my js file I create a function:
Quote:$('.toggleContent').click(function(){
$.ajax({
url: "/blog",
success: function(data){
$('#content').html(data);
}
});
return false;
});

so I just replace the content with a new file. Everything works fine on this stage.
my requested page looks like this:
Code:
<a href="/index" class="toggleContent">toggle</a>
  <p>some text</p>

but my next step is to toggle this back. but jQuery can't locate toggleContent class in a replaced content.

So is there a way not load new js file with just a clone function of ajax call, but somehow to refresh DOM?


lost in jQuery - El Forum - 01-23-2009

[eluser]zovar[/eluser]
Sorry, is it possible to move this topic to Code and Application Development category?


lost in jQuery - El Forum - 01-23-2009

[eluser]bobbybaboon[/eluser]
In jquery 1.3 you can add a live event to your click function.
Live events documentation
If you're using an older version of jquery you can use the jquery livequery plugin
Live query plugin
The docs should be able to help you out. Otherwise this tutorial at Nettuts.com might be helpful.


lost in jQuery - El Forum - 01-23-2009

[eluser]zovar[/eluser]
All right, thank you, that's exactly what I need.