Links to Jquery UI accordion on the same page
I am trying to create links on the same page as an a开发者_如何学编程ccordion that will open the appropriate section and bring it to the top of the page. I am initializing the according via the code below and using the default set up for the accordion.
$("#accordion").accordion({
autoHeight: false,
collapsible: true,
navigation: true,
active: false
});
Any help with this is greatly appreciated!
Using the following you can target specific areas of an accordion to open. active: 1
is the area you want to open.
(Note: The count starts from 0 if I remember correctly, so in this case your second area within the accordion will open!)
$("#accordion").accordion({ active: 1 });
If you wanted to trigger this from clicking on a link somewhere on the same page, you could do something like the following
The jQuery
$("#exampleLink").click(function() {
$("#accordion").accordion({ active: 1 });
//remove return false; if you want it to jump to the top of the page when clicked
return false;
});
The HTML
<a href="#" id="exampleLink">Link Text</a>
Hope that helps
精彩评论