开发者

jQuery accordion slideToggle problem

I have an accordion where html loads live via ajax in a div. The div has a close button where you can remove it from dom when its clicked. When the div is created again without reloading the page then the slideToggle triggers twice up and down and then hides the content.

Here is html loaded via ajax:

<div id="slidetoggle">
  <h3>Title</h3>
  <p>content</p>

  <h3>Title</h3>
  <p>content</p>

  *..and so on..*

 </div>

Here is jquery:

$开发者_StackOverflow社区("#slidetoggle p:not(:first)").hide();

$("#slidetoggle h3").live('click', function(){
  $(this).next("p").slideToggle("slow").siblings("p:visible").slideUp("slow");
});

Thanks in advance!


Use .die() when remove nodes from DOM.


I suggest to use jquery ui accordian.

Have a look http://jqueryui.com/demos/accordion/


Try:

 $(document).off('click', '#slidetoggle h3').on('click', '#slidetoggle h3',function(e) {
   ...
 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜