Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>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 <code>filter()</code></p> <pre><code>$("#contact, #address, #email, #sales, #equipment, #notes, #marketingdata") .filter(":not(:has(.selected))") .accordion("activate", 0) ; </code></pre> <p>Is that what you were after?</p> <hr> <p>Edit to explain that filter function:</p> <p>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.</p> <p>In this case the query removes anything which doesn't (<code>:not</code>) have (<code>:has</code>) a child with class "selected" (<code>.selected</code>). I used the <code>.selected</code> selector here because that's what the accordion adds to the currently-open panel.</p> <p>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".</p> <pre><code>$(".accord:not(:has(.selected))").accordion("activate", 0); </code></pre> <p>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.</p> <p>The documentation for filter is here: <a href="http://docs.jquery.com/Traversing/filter" rel="noreferrer">http://docs.jquery.com/Traversing/filter</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload