Welcome Guest, Not a member yet? Register   Sign In
lost in jQuery
#1

[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?
#2

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

[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.
#4

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




Theme © iAndrew 2016 - Forum software by © MyBB