开发者

jQuery UI's accordion not expanded

开发者 https://www.devze.com 2023-03-13 15:27 出处:网络
I have a page where I use accordion widget. I need to be able to open a page and have an accordion expanded on a particular section. jQuery UI is providing an option for it: active, which is what I us

I have a page where I use accordion widget. I need to be able to open a page and have an accordion expanded on a particular section. jQuery UI is providing an option for it: active, which is what I use. however when I open a page the accordion开发者_运维知识库 is collapsed. What am I missing?

My code looks like this when I view page source:

$("#accordion").accordion({
    header: "h3",
    active: 3,
    collapsible: true,
    autoHeight: true
});


I'm not sure, but I'll take a shot.

You have to wrap the code in a $(function() { }); block. Like this:

<script>
     $(function() {
          $("#accordion").accordion({
               header: "h3",
               active: 3,
               collapsible: true,
               autoHeight: true
          });
     });
</script>

I hope this helps.


it'd be great if you could post a jsFiddle... or just the page itself on the web.

i would say do this:

$(document).ready(function(){
   $(function() {
          $("#accordion").accordion({
               header: "h3",
               active: 3,
               collapsible: true,
               autoHeight: true
          });
     });
});

this makes your code run only when the document is fully loaded. Your problem might be that jQuery is trying to expand something that doesn't exist yet.

0

精彩评论

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

关注公众号