Reputation: 512
I have a series of accordions on my page. I would like to use anchor links to link to a piece of content within another accordion item.
My entire code is here: https://jsfiddle.net/hgfz285d/
As you will see I have 3 Accordions. In accordion 2 I have the content I want to link to wrapped in a span
with the ID
of link1
. In my third accordion I have a link targeting href="#link1"
. How can I open the targeted accordion and scroll to the content?
Upvotes: 1
Views: 210
Reputation: 3113
You can leverage click
event on .expand
, since you already have it working.
var id = jQuery(this).attr('href');
var handle = jQuery(id).closest('.accordian').find('.expand');
handle.click();
You also forgot to pass e
event variable.
Refactored JSFiddle here.
Upvotes: 1