Jquery Accordion to activate specific panels with anchor tags/url hash?

You'll want to tie in your server-side code with the activate() method which should let you dynamically show a panel based on what is passed as the index or selector: Activate a content part of the Accordion programmatically. The index can be a zero-indexed number to match the position of the header to close or a Selector matching an element. Pass false to close all (only possible with collapsible:true ) Example: If possible, instead of passing $_GET'id' pass the name of the selector matching the element that you want activated.

For example: $("#accordion"). Accordion("activate", "#") $_GET'tab' would be the name of the selector your passing. Of course, if the selector needs to be a class, just change the hash to a period If you wanted to have something activated based on a link like mysite.com/page#anchor you'll want to grab the hash with javascript when your page loads and use that hash (which would be the name of the selector that will activate your panel) in place of $_GET'id'.

You'll want to tie in your server-side code with the .activate() method which should let you dynamically show a panel based on what is passed as the index or selector: Activate a content part of the Accordion programmatically. The index can be a zero-indexed number to match the position of the header to close or a Selector matching an element. Pass false to close all (only possible with collapsible:true ).

Example: If possible, instead of passing $_GET'id', pass the name of the selector matching the element that you want activated. For example: $("#accordion"). Accordion("activate", "#"); $_GET'tab' would be the name of the selector your passing.

Of course, if the selector needs to be a class, just change the hash to a period. If you wanted to have something activated based on a link like mysite.com/page#anchor you'll want to grab the hash with javascript when your page loads and use that hash (which would be the name of the selector that will activate your panel) in place of $_GET'id'.

Thanks so much for your answer! Sounds like what I'm looking for, but I don't know how to carry it out -- do you have an example of what the changes to my code would look like? – essentialred 2 days ago You're welcome.

I've edited my answer to provide an example :) – Aaron 2 days ago Hm...for the code $("#accordion"). Accordion("activate", "#"); doesn't it have to be the id of the panel in order for it to work? For example, to activate the first panel the code is $("#accordion").

Accordion("activate", "0"); – essentialred 2 days ago Oh, yeah you can certainly use the indexes of the panels instead of a selector (with no quotes of course), but I was just trying to show that you can pass a selector around and use that to activate the panels instead of using the elements index. Also, what you said about using the id of the panel in order for it to work: it's not the id you're using if you're using numbers. It's the index of the element.

If you have 3 tabs, you'd have indexes of 0, 1, and 2. Hope that helps! – Aaron 2 days ago.

But wasn't able to correctly implement the answers. The above code allows me to have links on the main page that will activate the specified panel. The exlnk bit gives each panel a hash upon clicking it, which I read on this tutorial ( http://www.michaeljacobdavis.com/tutorials/statesavingaccordion.html ) would create state-saving, book-markable panels.

It assigns the hash, but it doesn't activate the panels or save them from closing on re-load. What I want is to be able to link externally to http://www.mysite.com/page#anchor and have it open the page with the appropriate panel open. My work-around to be able link from the accordion page is only so useful!

Thanks SO MUCH for any help...I have read every Q&A on this site related to the Accordion script and was not able to make any of the answers work. I am very very new to Jquery/Javascript, so answers that explain all the steps of implementation and where to place each suggested code would be wonderful.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions