Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Accordion and loading content through AJAX

Tags:

I would like to load the content under each jQuery accordion header using the jQuery load command. Currently, I have set this up as the following

$(function() {      $("#accordion").accordion({                   header: "h2",         active: false                   });      $("h2", "#accordion").click(function(e) {         var contentDiv = $(this).next("div");         contentDiv.load($(this).find("a").attr("href"));           });                     }); 

and the HTML (relevant snippet)

<div id="accordion">     <div>         <h2><a href="home.htm">Home</a></h2>         <div>            <!-- placeholder for content -->         </div>     </div>     <div>         <h2><a href="products.htm">Products</a></h2>         <div>            <!-- placeholder for content -->                </div>     </div> </div> 

Now this all works fine, but there is a problem in that loading content in this manner interrupts the slide down animation of the accordion plugin on some browsers (IE6), and on others (FF), the slide down animation does not occur.

I'm thinking that I would need to prevent the slide down animation from occurring until the content has loaded (using the load callback function) but am unsure how to hook this into the accordion plugin.

Any ideas greatly appreciated!

like image 552
Russ Cam Avatar asked Mar 14 '09 18:03

Russ Cam


1 Answers

Just a quick heads up.

None of these answers will work as expected with the latest API as since jQuery UI 1.9 the events change and changestart have been altered to 'activate' and 'beforeActivate' respectively.

Hope that saves someone a few minutes.

like image 83
Greg Barnes Avatar answered Sep 18 '22 07:09

Greg Barnes