-2

The accordion that is functioning is built-in shortcode within a WP theme. I have regular old anchors on an external page that link to this main page with several terms/definitions inside the accordion. I'd like the anchor tag to not only take the user to the listed term, but also open the accordion panel it's inside of, thus showing the definition.

I tried this unsuccessfully - http://jsfiddle.net/VZ3T5/5/

And now I've moved on to this but can't seem to get it to work either -

<script type="text/javascript">
var anchor = window.location.hash.substring(1);
$('.' + anchor).removeClass('active');
</script>
Michael Irigoyen
  • 21,233
  • 17
  • 82
  • 125
dutchie
  • 21
  • 1
  • 3
  • 2
    Can you share a bit of the code you've tried, any errors you're getting, etc? – pioto Apr 17 '15 at 18:55
  • javascript can read the url, you can have an if statement to test the url for things like a #anchor, and you can use javascript to open the accordion item. So yes, it's very possible, but without anything to go on you'll have to figure out those steps for your scenario. – RightClick Apr 17 '15 at 19:03

1 Answers1

0

One way you could activate a particular accordion tab is by using it's ID. So, you could use, for instance:

$("#accordion").accordion();
$("#accordion").accordion("option", "active", 2);

to activate the third tab after the accordion is "activated" (accordion tab elements are numbered from 0). There could be a lot of ways to do what (I think) you want to do:

Use an ID with the url of the page with the accordian, for instance:

www.domain.com/myaccordionpage.html#2

This way, after you activate your accordion in your JS, you can open the 3rd tab on your accordion element when this page loads:

$("#accordion").accordion("option", "active", parseInt(window.location.hash.substring(1)));

This could be one solution.

Ref: https://jqueryui.com/accordion/

gouthamr
  • 37
  • 7