admin管理员组文章数量:1425862
I am using jquery accordion and it works fine on initial page load, but then I have some ajax mands that reload part of the page, essentially the inner body of the page.
When this happens, the accordion is broken, since the reload i do is just replacing the innerHTML of almost the entire body field.
The script that loads the accordion is also included in the replaced HTML, but obviously that doesn't help.
How can I keep (or reinvoke) the accordion effect after replacing the innerHTML of my entire page?
<div class="art-Post-inner" id="ajaxWrapper">
<div id="accordion">
<h3><a href="#">Skärm 1</a></h3>
<div>
my accordion content
</div>
</div>
<script>
$(document).ready(function() {
$( '#accordion' ).accordion({
collapsible: true, active: false, autoHeight: false
});
});
</script>
This is the art that gets replaced entirely by setting the innerHTML of the div with id=ajaxWrapper.
i trust you see the problem.
I am using jquery accordion and it works fine on initial page load, but then I have some ajax mands that reload part of the page, essentially the inner body of the page.
When this happens, the accordion is broken, since the reload i do is just replacing the innerHTML of almost the entire body field.
The script that loads the accordion is also included in the replaced HTML, but obviously that doesn't help.
How can I keep (or reinvoke) the accordion effect after replacing the innerHTML of my entire page?
<div class="art-Post-inner" id="ajaxWrapper">
<div id="accordion">
<h3><a href="#">Skärm 1</a></h3>
<div>
my accordion content
</div>
</div>
<script>
$(document).ready(function() {
$( '#accordion' ).accordion({
collapsible: true, active: false, autoHeight: false
});
});
</script>
This is the art that gets replaced entirely by setting the innerHTML of the div with id=ajaxWrapper.
i trust you see the problem.
Share Improve this question edited Feb 4, 2012 at 23:13 mu is too short 435k71 gold badges859 silver badges818 bronze badges asked Feb 4, 2012 at 22:47 Matt WelanderMatt Welander 8,57825 gold badges96 silver badges146 bronze badges2 Answers
Reset to default 4use $( ".selector" ).accordion( "refresh" );
Put the jquery accordion function in the success callback of the .ajax
request:
Example:
var accordionOpts = {
collapsible: "true",
active: "false",
autoHeight: "false"
};
$('#accordion').accordion(accordionOpts);
$("#replaceContent").click(function() {
$.ajax({
type: 'POST',
cache: false,
data: {
html: "<div id='accordion'><h3><a href='#'>Skärm 2</a></h3><div>my accordion content</div></div>"
},
url: '/echo/html/',
success: function(data) {
$(".art-Post-inner").html(data);
$('#accordion').accordion(accordionOpts);
}
});
});
Fiddle: http://jsfiddle/6Scgc/3/
本文标签: javascriptjquery accordion broken after partial ajax page reloadStack Overflow
版权声明:本文标题:javascript - jquery accordion broken after partial ajax page reload - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745459407a2659253.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论