Jquery toggle with load()

Hi everybody,

I’d like to create a list in which the content divs can be opened and closed with the responding jquery function.

Could anyone give me a hint how I can load the content into the divs dynamically with jquery load function when I open it up with toggle ?

Thank you very much.

Regards
Ralf

Sure thing, by using [url=“http://api.jquery.com/load/”}.load()

Thanks for your reply. And how can I combine load with toggle ? Do I have to use load as callback of toggle ?

Looking forward for any further hints :slight_smile:

That would be a good idea. Even if the load request takes longer than it does for the toggle to occur, it could work better to wait until after the toggle has finished occurring,

This is how I would approach it
HTML


<a href="the_url_here" class="toggle_load" />Link Text</a>
<div class="load_target"></div>

JS


$('.toggle_load').click(function(event) {
     var url = $(this).attr('href');
     var target = $(this).next('.load_target');
     target.load(url, function() {
          target.slideDown('fast');
     });
     event.preventDefault();
});

I know this doesn’t toggle, but then you just add an if statement testing for the div’s current condition.

p.s: it’s late, code is untested, but I’m trying to help.:slight_smile: