简体   繁体   中英

Targeting instances of JQuery UI Accordion without knowing what they are

I have a site that uses jquery UI accordions on different pages. The script for these accordions is on the page in each case.

We're looking into daily site prints for all pages so we need those accordions to be fully expanded when we do the site print (we'll be doing this by detecting the site printer's userAgent string because they can issue a custom one).

The site printer can halt execution of javascript on a page to keep content fully expanded but we also use AJAX scripts so that would prevent content from loading.

So we need a script that targets any jquery accordions on a page and makes them fully expand. We have a custom.js file that is present on all pages so we could place a command there.

My question is, is it possible to target all instances of accordion objects without already knowing what they are? I'm looking at the possibility of putting a script in the custom.js file rather than having to rewrite all the JQuery accordion calls page by page (and trying to get everybody that adds stuff to the site to also remember to write a conditional userAgent based expand everytime they use an accordion).

Without seeing your code or knowing anything about your current HTML, you can try something like this:

$(".ui-widget.ui-accordion").each(function(index, elem){
  // Code that you want to execute on each Accordion
  // For example, we could disable each one:
  $(elem).accordion("disable");
});

I don't see a method to expand all panels at once. Likely, you would have to activate each panel.

Found this: jQuery UI Accordion Expand/Collapse All

It advises using the theming to make the accordion look correct, and then roll your own ability to expand all.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM