Jquery Accordion Close then Open

怎甘沉沦 提交于 2019-12-03 06:22:18

I'm not exactly sure what you're after, but this is my best guess. Out of all your accordions, you want the "open all" button to open all the accordions which are closed (that is, no section is showing). I'd do that by using filter()

$("#contact, #address, #email, #sales, #equipment, #notes, #marketingdata")
    .filter(":not(:has(.selected))")
    .accordion("activate", 0)
;

Is that what you were after?


Edit to explain that filter function:

The filter function just runs your current selection through a filter, removing anything which doesn't match. It has two different forms: one where you pass a regular jQuery query in, like i did above, and the other where you can define a function to filter. If the function returns false, then that element is removed.

In this case the query removes anything which doesn't (:not) have (:has) a child with class "selected" (.selected). I used the .selected selector here because that's what the accordion adds to the currently-open panel.

If you only had one accordion, or you gave each of your accordions some sort of identifier, such as a class name, then you could greatly reduce the entire script. Let's say that for each element you want to turn into an accordion, you give it the class "accord".

$(".accord:not(:has(.selected))").accordion("activate", 0);

This is much more legible and maintainable, since you can easily add more accordions in the future if you wish and this will handle it.

The documentation for filter is here: http://docs.jquery.com/Traversing/filter

Sil2
jQuery('#accordion').accordion({        
    active:-1,
});

I've had the same issue and resolved it with some short code leveraging JQuery's each() function to collapse while setting focus to item [0] so normal navigation can resume.

http://spstring.jeffthink.com/?p=49

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!