Yup, Yet another JQuery Accordion Plugin
Over two years after posting this simple JQuery accordion menu and later on an improved JQuery accordion menu I'm still receiving epic amounts of traffic on these posts. New comments keep getting posted every week as well. When I posted these I never even dreamed they would draw this much attention and they were never intended to be more than just quick code snippets. Apparently I was wrong. JQuery is going extremely strong and somehow it seems I managed to fill some sort of void with my little accordion code snippet.
Questions are being asked, requests are made for things the snippet won't do without modifications and most importantly, problems are being reported with newer versions of JQuery. Because of all this I decided to once again do a new version of this little JQuery accordion. I tried to address most of the issues reported by readers and add some new features. Let's take a look at version 3, now in JQuery plugin flavor.
UPDATE: fixed 2 bugs reported in the comments. See my comment for details.
UPDATE 2: (April 11, 2010): fixed a bug causing erratic behavior in nested accordions.
Get the code
New Features
For those who already know the previous versions I'll start with new things this version can do that the old one can't:
- Nested accordions. Yep, they work. It's now possible to have an accordion inside an accordion item without the two disrupting eachother. My advice was and still is: use with caution. If not styled right this can be extremely confusing for your users.
- Panels that hold other things than lists. You can now add anything. This is handy for those 'Apple style' accordions with content in each panel.
- An 'active' class is now added to each toggle that has an open panel below it. Nice to provide an extra visual cue to your users.
- Built according to the JQuery Plugin pattern
- No more need for menus to have an ID
- Any panel can be opened at page load time by using the class name expand on the list item that holds the toggle + panel you want to be opened
Cool features that were already there:
- Collapsible accordion: only one panel can be open at any given time but this one panel can be collapsed in order for the entire accordion to be collapsible
- Can function as a regular set of toggle panels where any panel can be open or closed
How to use the JQuery accordion plugin
Create markup that looks like this:
<ul class="menu"><li><a href="#">Item 1</a><ul class="acitem"><li>...</li><li>...</li><li>...</li></ul></li><li><a href="#">Item 2</a><ul class="acitem"><li>...</li><li>...</li><li>...</li><li>...</li></ul></li></ul>
As you can see, the main UL element containing the entire accordion needs to have menu as one of it's class names. Secondly, each item that serves as a toggle panel needs to have the class name acitem. The element with class="acitem" can be any element. It doesn't need to be a list of links. You can use a DIV element containing any kind of content if you like.
Expanding items at page load time
In order to have any item expanded as the page loads, add the class name expand to the panel you want to be expanded. For example:
<ul class="menu"><li class="expand"><a href="#">Item 1</a><ul class="acitem"><li>...</li>......
Keeping state
In the comments below the previous version of this plugin, various people were asking for a way to maintain state. I even made a (messy) attempt to do this in Javascript but... I think it's wrong. It's much better (and easier) to maintain state in the code that controls your page markup. Now that you can have any panel expanded at page load time by means of the expand class shown in the above example you can control the state of your accordions by having your page generation code set this class. Nice, easy and no cookie crumbs all over the floor.
Wrapping it up
Like I mentioned at the start of this post, JQuery is going stronger than ever. As much as I love YUI and the accordion widget I built with it there's simply way more interest in the JQuery one. And that's why I just had to do an update to it.
CSS
Important note: The CSS in on the example page is not perfect and certainly not pretty. It's strictly intended for demonstration purposes. This also means I didn't vigorously make it perfect for all browsers. You're strongly encouraged to use your own styling for your accordion menus.
Filed under: programming
Number of comments:
Number of trackbacks: 








At 01 March '10 - 08:31 WebSlingers wrote:
At 02 March '10 - 00:38 Horatiu wrote:
I would like it to stay this way until user chooses to click on another link in a different section.
10x for your time.
At 02 March '10 - 10:58 Marco wrote:
At 02 March '10 - 11:10 mil wrote:
Is there a way when the menu link item is cliked and collapsed to make it stay collapsed and different color after is clicked, so the visitors know where they are at?
At 03 March '10 - 00:04 Morpheus wrote:
Could have never achieved this on my own.
I’m trying to get the collapsible/expandable items (in your example menu “weblog tools” “programming languages” etc. ) to link to a page inside my site and that’s giving me quite some problems.
What I’m trying to achieve is that for example “home” would link back to index.html and other menu items would also link to other areas in the site, expand and have, let’s say for examples sake, anchor links to headlines in that particular area of my site.
Any suggestions on how to manage this?
Forever in you gratitude,
Morpheus
At 03 March '10 - 04:20 shuthichi wrote:
how can i add links to the level one menu items?
For example:
1.
2.
3. Item 1
4.
5. ...
6. ...
7. ...
8.
9.
10.
11. Item 2
12.
13. ...
14. ...
15. ...
16. ...
17.
18.
19.
I’m not able to get the link working…
Thank for a short reply.
At 03 March '10 - 04:25 shuthichi wrote:
how can i add links to the level one menu items?
For example:
Item 1
...
...
...
Item 2
...
...
...
...
I’m not able to get the link working…
Thank for a short reply.
At 03 March '10 - 04:48 shuthichi wrote:
how can i add links to the level one menu items?
In the example only the level two itemlinks works correct.
I’m not able to get the link working…
Thank for a short reply.
At 03 March '10 - 07:40 Marco wrote:
At 03 March '10 - 08:23 Marco wrote:
Somehow I’m not sure if that’s what you mean though. If not please elaborate!
At 04 March '10 - 00:23 Horatiu wrote:
In the “Collapsible accordion with first item expanded at page load” example we have 4 parents that have children: “Weblog Tools”, “Programming Languages”, “Cool Stuff” and “Search Engines”.
Let`s say I`ve clicked on Cool Stuff parent. Now the menu expands and I can see it`s children: “Bookalicious”, “Apple”, “Nikon”, etc.
They are very nice kids and all, but if I click on one of the links, let`s say “Nikon”, the page loads and the menu closes. I`d like very much “Cool Stuff” parent to remain expanded after the page loads. If I use the “expand” class, this parent will stay forever expanded and this is not cool, because I`d like to check out other parents on the site and I`d like them to expand/close as soon as I click on them.
It will be also nice if a parent opens a link and expand at the same time when clicked on. I`ve added a line of code to accomplish that and then the parent opened the link but didn`t expand.
If anyone can help with this please do so.
P.S. Very nice snippet, will be perfect with this functionality added.
At 04 March '10 - 01:07 Marco wrote:
When I click ‘Nikon’ in the scenario you mention I LEAVE the page and go to the Nikon website. I’m not sure what the purpose would be of opening a panel AND visiting the link (and therefore leaving the page).
I guess I’m still missing the point :(
Feel free to point me to an example page with your modified code. Maybe that will make me understand what you need…
At 04 March '10 - 02:56 Morpheus wrote:
What I meant was that once I had applied your code to my navigation and styled the css to my liking(basically just text visible, no background colors), the top-level tabs didn’t link anywhere, even if I gave the correct url:s. (well, this could be me assuming too much.. =) )
Ah, looks like I didn’t mention that I’m trying to use your code as a means of navigation on just my site. I don’t need to link to other sites.
Site structure is generic, Home, About me, Gallery, Contact, etc. So:
Home
...other subpage or anchor tag
...other subpage or anchor tag
...other subpage or anchor tag
About me
...other subpage or anchor tag
...other subpage or anchor tag
and so on and so forth.
Home, About me and other top-level accordion tabs fail to link, i.e. navigation from Home (index.html) to About me (about.html) was not succeeded, unless I add separate child elements for these in to the menu. So:
Home
...home
...other subpage or anchor tag
...other subpage or anchor tag
About me
...about me
...other subpage or anchor tag
I don’t know, maybe it’s not even supposed to function like I see it, but it just seem a bit redundant to have to add “home” under “Home” etc. to navigate on site? Am I thinking this backwards? Is it possible to add link finctions to the parent buttons that expand the accordions?
Gratefully,
Morpheus
At 04 March '10 - 02:59 Henk wrote:
At 04 March '10 - 04:05 Horatiu wrote:
In your scenario, all the links point to external websites. In my scenario, all the links point to internal website pages. Let`s assume we have this website structure:
Home page
Section#1
Child#1.1
Child#1.2
Section#2
Child#2.1
Child#2.2
.....
Let`s also assume that the visitor enters the URL of our website and the browser loads the index page. Now, the visitor messes up with our menu, because he likes closing and expanding the menu sections.
But, clicking on Section#1 link only expands the menu and the visitor still sees the index page. I would like him to see the section#1 page, that`s why I need this menu to expand and point to section#1 page at the same time, when the link is clicked.
Now let`s assume that the visitor clicks on Child#1.2 link. The page child#1.2 loads, the parent Section#1 (parent menu) closes, the visitor spends a little time reading the content of the page, and short after he forgets what section he was visiting because the parent is closed instead of being expanded and the child link highlighted.
Well, i hope you understand my scenario.
At 04 March '10 - 14:41 Marco wrote:
Horatiu, in your case I think you need to create some logic in your pages that loads the menu with the appropriate section opened for each page you’re on.
This means that on the Section 1 page the LI element containing the section 1 submenu has the ‘expand’ class name in the markup and on the Section 2 page the LI element containing the section 2 submenu has the ‘expand’ class name in the markup.
At 04 March '10 - 23:03 Horatiu wrote:
Thank you for your reply. I already tried using the ‘expand’ class but that`s not it. Using it on the tags would only expand both sections when the page loads.
However, I did more research on the Internet and I came across “Urban Grey Accordion”, which has it all.
Thank you again for your time, and good luck.
At 05 March '10 - 09:49 Marco wrote:
At 05 March '10 - 12:47 Michele wrote:
One question, is there a way around the awkward moment when the page loads and the accordion appears fully exploded for a split second. It seems like this is worse on pages where I’m using a flash player and not at all noticeable on pages with just text information.
I keep thinking there is a really simple solution that I’m missing.
At 08 March '10 - 03:22 Steve wrote:
On your demo page, if I click a section to expand it and then very quickly click the section below it, it’s possible to open two sections at the same time. The second section then remains open no matter what you click.
Also, if all the sections are the same height, is it possible to stop the stuttering, jumping effect (most noticeable at the bottom of the accordion) that happens when you click to open a section?
At 10 March '10 - 08:42 dikobraz wrote:
At 10 March '10 - 09:02 Marco wrote:
@Steve probably. Will look into this too.
@dikobraz as you can see in the demos, open sections have their toggle colored red. This is done through the active class with is added / removed to the toggle, styled with CSS. You can use this hook to add / – signs or any other graphical open/close indicator.
At 10 March '10 - 09:08 dikobraz wrote:
Programming Languages
PHP
Ruby
What if you wanted the user to be able to click on the words Programming Languages and have them go to a page of your site called Programming Languages (instead of expanding the menu)? To expand the menu, they’d click on a or a > next to the heading. Is that doable? Something like this:
Programming Languages
At 10 March '10 - 09:14 dikobraz wrote:
At 10 March '10 - 10:20 Rika_G. wrote:
Thank you for this nice menu.
I’d love to use the non-accordion (#3 in the demo page) one with expand states. But I have one simple issue.
It seems the link is not working. I have applied this script to my site and tried the same, still doesn’t get linked.
I did the same coding to my site, and I get the same result.
I am currently testing my site with Safari4 and FireFox3.5.8.
What could be the solution?
The demo page I’m looking at is;
http://www.i-marco.nl/weblog/jquery-acco..
Really appreciate you sharing your knowledge.
At 10 March '10 - 13:53 EJ wrote:
At 11 March '10 - 14:22 Shawn wrote:
At 12 March '10 - 13:43 JasonTC wrote:
Thank you in advance for your time.
- Jason
At 13 March '10 - 07:21 Beben wrote:
At 14 March '10 - 11:20 Marco wrote:
I promise to look into the issues as soon as I can. I have family over from Holland at the moment so bear with me for a bit!
At 15 March '10 - 22:04 Marco wrote:
1: The non-working link-only items now work
2: The highlighting issue as reported by EJ has been fixed.
I have updated the demo page and the zip file.
Thanks for the reports guys!
Then to answer dikobraz’ question: Yes this is doable with modifications. However it’s rather poor in terms of usability so I’m not planning to implement this.
At 16 March '10 - 10:34 EJ wrote:
At 16 March '10 - 13:57 Shawn wrote:
At 16 March '10 - 16:26 Marco wrote:
At 17 March '10 - 10:50 John wrote:
(function($) {
// your plugin here
})(jQuery);
?
I’m just getting started with jQuery, so I’m not sure if this is correct.
At 18 March '10 - 17:30 Steven wrote:
Thanks for the great Accordion Plugin
Im trying to use it as a means of navigation for a site, and all Is working well, the only issue I have is whereby the Single Links in the menu (i.e. the ‘Home’ link from your demo) do not stay their active colour (Red in Demo) after you have clicked on them.
The links that have submenus (i.e. the ‘Weblog Tools’ link from your demo) however do stay their active colour (red) after you have clicked on them.
Is there any way for the the single links to retain their active colour? As I feel this is quite important for the navigation.
Thank you for your help!
Steven.
At 24 March '10 - 03:25 James Bartlett wrote:
Everything is fine and dandy until I try to expand one of the submenus – it opens and then immediately collapses. From what I can tell with a bit of debugging it calls slideUp then slideDown then slideUp again, so there’s probably some logic I need to look at. Any ideas?
At 24 March '10 - 10:24 Marco wrote:
At 25 March '10 - 11:10 Alex wrote:
The nested accordion is working perfectly for me right now. The one problem I am running into is keeping the nested menu expanded on page load.
My structure is Parent Category > Sub Category > Product
When they click on the product, it goes the the product page, and I apply the expand class to that “Sub Category” menu so it stays open, but it isnt working.
Can you not keep a nested accordion open?
Thanks for the help,
Alex
At 25 March '10 - 15:15 Wendy wrote:
Besides your generosity with your awesome menu, you are amazing for being so patience with everyone asking niggly little questions about it.
Having said that, I have a niggly little question: could this be used in a horizontal orientation, i.e., a dropline menu, or would this require major mod?
Thanks, and thanks again for all your hard work, and your patience!
At 30 March '10 - 09:26 wnw0031 wrote:
Another niggly little question:
Can the menu function like this: when the user clicks on a tab.. it collapse…the user clicks a link under the tab and goes to that page. While on the page. the menu remains in its collapsed state but only for that heading.
How can i accomplish this.
At 31 March '10 - 08:38 John Kalnin wrote:
If you use a list with an li class=“home_sub” and the page’s body has an id=“home” you can make the CSS do some like:
#home li.home_sub{
/* do something different for this list item as it is active */
}
Thanks for any help or suggestions.
At 01 April '10 - 05:09 Michael wrote:
These are the available CSS classes (or ids):
ul.left_menu
ul.left_menu li
ul.left_menu li.level1
...
ul.left_menu li.level6
ul.left_menu ul
ul.left_menu ul li
ul.left_menu a
ul.left_menu a:hover
Thanks in advance!
Kind regards, Michael
At 04 April '10 - 10:32 Jason Imani wrote:
Thanks for accordion script. It’s been super easy to implement. I have a quick question about how to nest an accordion within another accordion, could you describe the html structure necessary to do this? I’ve tried everything and I just can’t get it to work.
Thank you again!
At 04 April '10 - 10:43 Jason Imani wrote:
I got it figured out…gets a little confusing with many level of ul’s, li’s…
Thank you again for the awesome script!
At 08 April '10 - 11:01 rafa wrote:
how can i use latin charcters at the links of the menu?
Thanks
At 09 April '10 - 00:03 Rob wrote:
I just want to ask if there’s a way to keep the one of the category unclosed after its submenu is clicked.
At 23 April '10 - 07:19 J.M. Suijkerbuijk wrote:
Thanks in advance!
At 23 April '10 - 08:24 J.M. Suijkerbuijk wrote:
At 23 April '10 - 11:27 Jean-Marc wrote:
Nice plugin ! I would like to know if it’s limited to 20 items ?
Thanks !
At 28 April '10 - 19:06 TiM wrote:
At 28 April '10 - 20:57 Scott wrote:
Thanks, Scott
At 03 May '10 - 06:13 Velimir wrote:
This accordion menu is really, really great, and I implement it into my site.
But, I have sam problem as Morpheus (pu some link in level 1)
Can you tell us about that?
At 06 May '10 - 07:02 David H wrote:
Thanks very much for taking an interest and developing the accordion code.
I would like to adapt this to the functionality I see in the sidebar at DMXZone at this page
http://www.dmxzone.com/go?17207#Features..
on the left the Green box that says “Related Items”
The mouse simply passes over, no click required…mouse over a Category and it either slides up or down to reveal sub-categories or links to topics or pages.
I want to somehow get this functionality into WordPress and I like it better than having to click on something to trigger a movement.
It seems your code would be adaptable somehow to get this nice function.
At 07 May '10 - 06:21 Tom wrote:
Great menu !
Tom
At 10 May '10 - 12:17 didier De Jaeger wrote:
Anybody who has an idea to get this to work?
header.php refers to menu.js, jquery-1.4.2.min.js and style.css.
menu ul has class=“menu”
menu has now everything expanded.
with older jquery version it would leave the active childrens open.
all help is greatly appreciated !
didier
At 10 May '10 - 12:19 didier De Jaeger wrote:
older version of jquery WOULDN’T leave active children open…
At 13 May '10 - 12:14 Josh wrote:
All I wanted to do here is say thanks for not only making this in the first place, but being active in furthering it. That takes a pretty cool person…
Josh
At 14 May '10 - 09:16 ldeng76 wrote:
ul.nestedmenu , ul.nestedmenu ul {
width: 14.65em !important ;
}
At 20 May '10 - 04:15 Tarak wrote:
I am facing problem when page is loaded after menu item link is clicked. I need to show the item clicked in different color, so user can know which item they clicked. can this be possible ?
At 21 May '10 - 01:08 Marco wrote:
At 05 June '10 - 05:34 DD wrote:
I like your menu!!
But I’ve a problem with IE…
If I load your demo page, all menus are open for a second, then they are close.
How solve this problem?
Thanks
At 05 June '10 - 10:37 DD wrote:
How can solve it?
Thanks
At 10 June '10 - 12:13 fiu wrote:
Your menu is just awesome :)
but unfortunately i have question … is there a way to achieve an active-status for sub-menus too?
greets
thanks
At 11 June '10 - 09:59 Bob Ainsbury wrote:
Is there a way (when selecting an item with no children) that:
a) The previously expanded menu item collapses (since focus/selection has changed)
b) The selected item (with no children) has “focus”
Thanks!
Bob
p.s. If not, please contact me to see if I can hire you to do that.
At 14 June '10 - 02:41 effemme wrote:
PivotX
WordPress
Textpattern
Typo
how to set color at description of submenu?
i want that
PivotX have a different style (different color) ?
i try with add in style css
.click{
text-decoration: none;
background: #FFFFFF;
color: #FF0000;
font-weight:bold;
}
but color remain with setting
ul.menu a.active, ul.menu ul.menu li a.active, ul.menu a.active:hover, ul.menu ul.menu li a.active:hover {
text-decoration: none;
background: #FFFFFF;
color: #000000;
font-weight:bold;
}
At 16 June '10 - 12:02 BobDole wrote:
Here’s my feedback:
- You should include documentation on how change the functionality from responding to a click, to responding to a rollover, since clicking on a menu item to bring up another menu item is really non-intuitive and not very user friendly. Most drop down menu systems respond to rollover for main elements, and clicks for subelements/action items.
- You should include a ‘mouseOut’ event that collapses the menus if they’re not in use, or if another menu item is open. I can click on multiple menus at the same time (this is a particularly bad problem when the script is changed to respond on hover). Include sensitivity settings that will close other menus that are open when a new menu is clicked/hovered over, and that will close all open menus after a certain amount of time of not being in use.
At 22 June '10 - 20:22 Ahmed Hadra wrote:
Problem: CSS works fine but al items of the menu were open. This is because the wordpress theme calls function from the header.php. In wordpress 2.9.2 this function calls an older version of jquery.
Solution: I updated the jquery version called by wordpress following the steps that i found on this page
http://bloggingabout.com/howto-updated-j..
Hope it works. did for me :)
By the way. Thanks for this great file!!
At 03 July '10 - 06:28 Antnan Mpekir wrote:
I have a situation about this menu. I realized that when we click the link from menu it goes to another page. I want to use it on a page that the pages will shown on the right side and the menu on the left all the time. But when i try to do that the clicked child page opening but the menu resets or something and only parent menus been shown. How will it be possible to make the menu stand on the clicked section when i click to child link.
Sorry for my bad english :) hope you understand the issue..
thanks in advance
At 04 July '10 - 22:10 Eliza wrote:
THANKYOU :)
At 18 July '10 - 13:40 uogecko wrote:
I know that the script automatically changes the ul li a (link) tag class to “active” however I’d really like the script to alter the ul li (list-item) tag class in the same manner.
I’m not very well versed in JQuery – can you tell me what changes need to be made to your script in order to accomplish this?
Thanks!
At 21 July '10 - 10:33 Jay wrote:
Great additions to an already great accordion. Is there a reason you decided not to include the jQuery cookie plugin this time around? I’m gonna see if I can work it into this new one referring to the old one. I’m no jQuery master but I understand it. Gonna give it a whirl.
Thanks again. Great work.
At 24 July '10 - 08:25 steven wrote:
Only one question. I saw it was asked several times, but i can’t find the answer:
Is it posible to set up a link to the first level?
In this exampel http://users.telenet.be/stevenenann/para.. there have to open a page in the middle section when you click for example ‘bibliotheek’ or ‘vorming’. Just like the one’s on the second level.
Thanks a lot!!
At 24 July '10 - 15:34 Simon wrote:
At 10 August '10 - 07:14 Stephanie wrote:
Section 1
subsection 1.1
subsection 1.2
Section 2
subsection 2.1
subsection 2.2
Section 3
subsection 3.1
subsection 3.2
I have 3 sections and up to 15 pages in each. Right now, I just have 3 versions of the menu and highlight the appropriate “section” manually. But this doesn’t highlight the page and I don’t want to have 50 versions of the list because updating every instance is a nightmare when things change.
I’m hoping that someone has done, or can offer a better way of doing this. Perhaps setting a variable on the page or some other way of informing the menu what to style as active/selected. I’m limited to only using html, css or javascript.
I have just (in the last 2 weeks) discovered jquery and though I can usually get done what I need to (by following examples/demos) my coding skills are just are not that great. If anyone has some explicit instructions or examples, I would be very grateful.
At 12 August '10 - 06:58 NNN wrote:
At 12 August '10 - 08:27 Frank wrote:
Great and clean. Thanks.
Is there a way (when selecting an item with no children) that:
a) The previously expanded menu item collapses (since focus/selection has changed)
b) The selected item (with no children) has “focus”
Thanks!
Bob
p.s. If not, please contact me to see if I can hire you to do that
At 20 August '10 - 07:10 John Kalnin wrote:
document.getElementById(“id_of_li_you_want_expanded”).className = “ expand”;
Now, you can use one menu system as an include and have the page content expand the correct menu option for you. Hope this makes sense – see it in action here:
http://www.lsac.org/JD/Think/getting-sta..
The included menu file has no “expand” class on any of the menu items. The page loads and that javascript code expands the correct section. This way I have one menu file for each section of the site making managing it 1000x easier.
You are the man!
At 01 September '10 - 10:24 bluantinoo wrote:
It would be just perfect if there was the possibility to let people close the submennu expanded just clicking on active links, exactly where they clicked to open it….
i tried to change a bit your script, but with no success :(
At 01 September '10 - 10:33 bluantinoo wrote:
you can delete my comment, or just leave the part where i say “very nice menu” ;)
At 08 September '10 - 08:55 Sparky wrote:
At 19 September '10 - 12:36 Uwe wrote:
I try to build a site with it, but i face a problem that is probably only due to my lack of experience. My menu has the following structure :
HOME
ITEMS – ITEM_1 – ITEM_2
and so on. Now, when i am on page HOME (home.html) and the user clicks on ITEMS, i want the page items.html to open plus the ITEM – menu to expand.
I’ve changed the href before the ul from # to items.html, but the new page won’t load.
Am i missing something?
At 20 September '10 - 09:26 Kristin wrote:
Thanks for all your work on this menu. It was very easy to implement and it looks like my version has several of the above mentioned bugs resolved.
There is a question that has been asked several times above and seems very basic to usability, yet I don’t see a solution posted by anyone.
How would we make the parent item link to a category page even when it has child sections? In my case, I’ve got:
Home
About
– sub-menu item
– sub-menu item
Services
– sub-menu item
– sub-menu item
Contact
Etc.
When I click on ‘About’ the menu expands, but the user remains on the page they were on. Most users would expect to go to a new page when they click on a link in the menu. I had intended to have a unique ‘About’ page, then sub-sections as well. Even if the first child served as the primary ‘About’ page, that would work as well. The most important factor is that when somebody clicks ‘About’, I need it to not only expand the menu, but also lead the user to a new page (ideally the ‘About’ page, but could be the 1st sub-menu item under ‘About’).
I hope this makes the problem more clear so you can let us know if there is a solution.
Thanks!
At 22 September '10 - 02:00 Orneis wrote:
1) How do you use “collapsible” class? I would like to be able to close an open menu by clicking again on the item. This is how I did it:
Home
About us
Item 1
Item 2
Item 3
Item 4
...
But it wont work.
2) I have tried using “hover” instead of “click”. It also works but I have a lot of sub-menus and everything opens too fast, it’s a bit disturbing. How can I add a delay before it opens?
3) Again… on the “hover” issue, how can I make an opened menu close but this time on a click?
Thanking you in advance,
Orneis
At 27 September '10 - 14:41 Jay wrote:
Step 1. In the parent tag specify the desired url instead of #.
Step 2. In menu.js add the following code before each of the “return false;” statements.
if (!typeof $(this).closest(‘a’).attr(‘href’) == ‘undefined’) {
window.location.href = $(this).closest(‘a’).attr(‘href’);
}
This will force the page to load after the menu expands. Additional code is still required to keep that menu “state” after the page loads however.
As an aside, do we really need return false, or would event.preventDefault(); be better? Is there any need for event.stopPropagation(); as well?
At 21 October '10 - 06:47 Sal wrote:
I’m trying to use your beautiful script and I want bring you a bug on z-index behavior when in the same page is used the ModalPopupExtender AjaxToolkit. I set the css z-index of my popup with a very high value (100000) and css z-index of Jquery menu at 1 … Unfortunately the menu remains on top and isn’t dominated by the brackgroud popup … any ideas on this?
Bye! :)
At 21 October '10 - 11:25 jared wrote:
At 21 October '10 - 14:09 cakephper wrote:
At 29 October '10 - 12:24 Greg wrote:
Services – Link 1 – Link 2
When I expand a list (Services) and click a menu item (Link 1) I would like the Services list still expanded on the Link 1 page, so the user knows where they are. This worked in your older version. The problem I had with the older version, is if I went to the Link 1 page, and then back to the home page, the Services list remained open, and I wanted all of the lists back to their default closed state.
Can I have both?
At 08 November '10 - 09:39 melly wrote:
how I can prevent shuts myself it that the assets submenu in the side change? ( Sorry for my Bad English )
Code:
function initMenus() {
$(’.children’, this).hide();
$(‘ul.menu ul’).hide();
$.each($(‘ul.menu’), function(){
$(’.children li’).show();
$(’#’ this.id ‘.children current_page_parent li’).show();
});
$(‘ul.menu li a’).click(
function() {
var checkElement = $(this).next();
var parent = this.parentNode.parentNode.id;
if((checkElement.is(‘ul’))
At 10 November '10 - 13:27 Tae wrote:
related to some of the comments above, i’d recommend support for the hoverIntent plugin for better UX: http://plugins.jquery.com/project/hoverI..
i’d also recommend adding visual indicators (such as arrows) to the examples to indicate which parent items have child items – and when the submenu is shown, the arrow should point down. right now, you have text labels that say something like “no submenu” which is not elegant at all.
At 19 November '10 - 13:53 designgrrl wrote:
Using this latest version of your menu, is there a way to use cookies to remember which item is expanded? Please help. And thanks in advance.
At 22 November '10 - 07:55 Ricardo Zea wrote:
I tried using a DIV inside the expandable area instead of UL/LIs but the menu breaks.
Any idea how that can be fixed/adapted?
Thanks,
At 02 December '10 - 10:51 Rick wrote:
Any help would be appreciated!!
At 09 December '10 - 03:11 jeff wrote:
Your menu seems not working when you place the scripts on the bottom of a page. I work with html5 and as recommanded I put all javascripts just before the closing
An idea ?
At 09 December '10 - 03:28 jeff wrote:
Thanks again
At 08 January '11 - 09:32 Evan wrote:
You can view a demo here and its code: http://jsbin.com/itibi4/9/
I have it working here using your previous code, but I’d like to migrate to your new code above.
http://jsbin.com/itibi4/5/
At 09 January '11 - 20:44 Evan wrote:
here is the finished code with expand all / collapse all:
http://jsbin.com/ucobo3/15
there’s one piece i can’t figure out is how to disable the active state from bullets when there’s no sub links such as those under section 3.
At 13 January '11 - 18:02 Evan wrote:
This demo includes the following: http://jsbin.com/ucobo3/24/
- active state now assigned to the unordered lists instead of “li a”. i read ‘uogecko’ asked for it to be assigned to the li. it’s more common for the active state to be assigned to the li. i needed this, too.
- Active and Inactive with toggling bullet arrow images. i thought this was a great way to show the active state.
- Expand All / Collapse All. The link will also swap its text!
- On page load, the two columns will load at equal height (even though they are not of equal height) and will expand and collapse when the accordion expands and collapses. This is a feature many need, but in most cases the accordion will experience an overflow if the plugin is not configured correctly as seen here: http://jsbin.com/ucobo3/22/
... i would love to see other enhancements such as: – when there is no sub menu, those arrows don’t toggle on expand all. – when there is more than one accordion menu and a list is expanded and left active, clicking on a second accordion in a different menu will collapse the active accordion from the previous menu. currently, each menu functions independently.
At 18 January '11 - 19:55 Austin wrote:
So, if I I jump straight onto the Ruby page, and it is a local page, the Programming Languages submenu would be expanded.
At 25 January '11 - 03:40 Max wrote:
I don’t know if this is possible with your menu accordion (number 4 on your demo page) but I will try to describe it: When I click on “cool stuff” the menu expands and it colors red, very nice. Then the user will click on “apple” and (in my case) a new page on my site loads (no external address). On this new page I would like to have the menu (menu needs to be visible on all pages) expanded on “cool stuff” and the item “apple” is also colored red.
Can this be done, and off course how?
Thanks,
Max
At 25 January '11 - 11:19 Ryan wrote:
I am using the “expand” class to specify which panel should be open on page load. I tried to also use “expand” on one of the children so that I could highlight the current page, but it didn’t work.
EXAMPLE:
Make – Audi – BWM – Mercedes Benz
Year – 2011 – 2010 – 2009
I want to expand the “Make” panel on page load (done) and also highlight the BMW child link to indicate the current page is BMW (not done).
I’m fairly new to jQuery. Can you advise how I can tweak your script to accomplish this?
At 10 February '11 - 06:06 Dennis wrote:
I was looking for a simple script to simulate the menu of the Wordpress admin console I could use in a CMS I’m developing.
And this is exactly what I was looking for.
Small issue was maintaining the open-state of the menus when switching pages. Which I solved by using a PHP $_GET procedure to check what page is loaded in the URI and then adding the ‘expand’ class to the LI element with that name. It’s probably not clean coding, but it does the trick (until I find a better way
One thing I’m less happy about is that all the menus are shown for a microsecond when loading a page, before they eventually are collapsed by the script. Which could probably be solved by a PHP procedure of loading the entire page into a buffer prior to putting it on the screen. I’m not sure if it’s possible but I’ll be crunching codes attempting to get around this.
For now, I’m happy with the result and look forward to any new features.
Thanks again!
(btw, my website is still under development until I get the CMS functioning. Check URL : myworkz.webatu.com/v2 for a small glimpse of what is to come)
At 14 February '11 - 11:04 Mario wrote:
Step 1. In the parent tag specify the desired url instead of #.
Step 2. In menu.js add the following code before each of the “return false;” statements.
if (!typeof $(this).closest(‘a’).attr(‘href’) == ‘undefined’) {
window.location.href = $(this).closest(‘a’).attr(‘href’);
}
I have added the code before each of the “return false;” but it does not work. Can everyone help me?
Thanks
At 23 February '11 - 07:42 Rob wrote:
Great accordion.
What I would like to do is return false on the actual menu links because I am using another script to load content into another element on the page. The hrefs are all # and my script is grabbing the ID of the LI elements to display the content in the DIV.
As it stands at the moment, it reloads the whole page, which I don’t want.
I have tried some changes in your code, but they break the functionality.
I hope you can help.
Many thanks.
Rob
At 09 March '11 - 02:44 James wrote:
Thanks very much for the code it is very useful.
Two questions,
1. I have a menu with only one panel that opens. I am trying to make this collapsible. As the UL’s both already have classes I cannot use it here, I have tried using it in the parent LI with no success and have tried wrapping a div with class collapsible round the child UL but still no success. Can you enlighten me as to the best way to do this please?
2. I want the script to “remember” the state it was in, so if someone opened the panel, if they click to another page the panel stays open. I thought about the expand class, but this would leave the panel open on entry which is not what I want.
I hope you are well, and applaud your generosity in sharing this excellent script.
Many thanks
At 10 March '11 - 00:32 Andreas wrote:
Question: A couple of my top level menu items (i.e. they have sub menu items) are linked to other pages. Is there any way to tell the script to follow these links, even though it’s supposed to expand the sub level?
At 21 March '11 - 19:13 layer26 wrote:
At 28 March '11 - 13:52 Nicola wrote:
for the problem raised by Michele on the 5th of March 2010, which i’ll briefly resume below:
“[...] when the page loads and the accordion appears fully exploded for a split second [...]”
and which I also had on IE, I have solved adding this piece of code in the document.ready() function of your script:
$(”#menu”).css(“display”,“block”);
and adding css style “display: none” to menu DIV, so that it’s shown only after being inited and collapsed by your script, in this way we prevent the wrong behaviour of being shown fully expanded for some seconds while page is being loaded on IE.
Cheers
At 08 April '11 - 07:38 Edge wrote:
Q1 Audio
href=“www.blah.com“id=“a”>Q1 Audio
Q1 Podcast (MP3)
AAA
BBB
CCC
DDD
EEE
FFF
GGG
HHH
III
Thanks again for the great plugin!.
At 12 April '11 - 04:01 anonimus wrote:
$(document).ready(function() {
$(‘ul#my-menu ul’).each(function(i) {
if ($.cookie(‘submenuMark-’ i)) {
$(this).show().prev().removeClass(‘collapsed’).addClass(‘expanded’);
}else {
$(this).hide().prev().removeClass(‘expanded’).addClass(‘collapsed’);
}
$(this).prev().addClass(‘collapsible’).click(function() {
var this_i = $(‘ul#my-menu ul’).index($(this).next());
if ($(this).next().css(‘display’) == ‘none’) {
$(this).next().slideDown(200, function () {
$(this).prev().removeClass(‘collapsed’).addClass(‘expanded’);
cookieSet(this_i);
});
}else {
$(this).next().slideUp(200, function () {
$(this).prev().removeClass(‘expanded’).addClass(‘collapsed’);
cookieDel(this_i);
$(this).find(‘ul’).each(function() {
$(this).hide(0, cookieDel($(‘ul#my-menu ul’).index($(this)))).prev().removeClass(‘expanded’).addClass(‘collapsed’);
});
});
}
return false;
});
});
});
function cookieSet(index) {
$.cookie(‘submenuMark-’ index, ‘opened’, {expires: null, path: ‘/’});
}
function cookieDel(index) {
$.cookie(‘submenuMark-’ index, null, {expires: null, path: ‘/’});
}
At 17 April '11 - 13:06 Bramick wrote:
You can’t wrap the anchor links that expand and collapse the accordion. for ex
Competition
Apartment A
Apartment B
Apartment C
Apartment D
Wrapping the anchor link in the h4 breaks the expand/collapse.
At 29 April '11 - 09:15 ken wrote:
What I ended up doing is calling the link through javascript, and then changing the css class with php. Works fine! This way I didn’t need to edit the javascript file at all.
here is the code: http://pastebin.com/mW8NQtku
btw this is using wordpress functions but you could write your own for any site.
At 11 May '11 - 07:59 Maria wrote:
This menu is sweet and exactly what i was looking for !
I have one problem : I already have a class “menu”, how is it possible to rename this in your script ?
I have tried to change it to menu2 in the menu.js file but it doesn’t work.
Could you please help me ?
Thank you !
At 13 May '11 - 10:31 Kay wrote:
Hi Marco,
The nested accordion is working perfectly for me right now. The one problem I am running into is keeping the nested menu expanded on page load.
My structure is Parent Category > Sub Category > Product
When they click on the product, it goes the the product page, and I apply the expand class to that “Sub Category” menu so it stays open, but it isnt working.
Can you not keep a nested accordion open?
Thanks for the help,
Alex
_______________________________________________________
I’m having the same issue. When Sub Category or Product is clicked, the menu closes/collapses. I only want the menu to close/collaspe when the Parent Category (top level) is clicked, not when sub-items are clicked. Is there a way to do this?
I love the menu and all your hard work. Amazing.
Kay
At 14 May '11 - 18:22 jw wrote:
Any idea why when adding rounded corners to the ul.menu would render strangely in Safari? Looks good in Chrome/FF.
It does this weird thing on the inside curve.
ul.menu li a, ul.menu ul.menu li a {
background: #333;
color: #fff;
padding: 0.5em;
-moz-border-radius:3px;
-webkit-border-radius:3px;
border-radius:3px;
}
At 14 May '11 - 19:59 jw wrote:
One or more comments are waiting for approval by me.