jQuery Accordion Trigger outside the element
I have a single drop down using the accordion jQuery plugin but I want the trigger to be a link that is way on the other side of the page, outside the e开发者_如何学Golement that drops down.
possible?
If I understand correcly, you want to trigger an accordion from an outside link.
You could use :
$( "#accordionId" ).accordion( "option", "active", idxToActivate );
A fast example :
HTML
<div id="accordion">
<h3><a href="#">First header</a></h3>
<div>First content</div>
<h3><a href="#">Second header</a></h3>
<div>Second content</div>
</div>
<a href='#' onclick='$( "#accordion" ).accordion( "option", "active", 1 );'>test</a>
SCRIPT
jQuery(document).ready(function(){
$('#accordion').accordion({});
});
Sure.
Say your triggers are like:
<a href="#" class="accordionLink">1</a>
<a href="#" class="accordionLink">2</a>
<a href="#" class="accordionLink">3</a>
Then you provide:
$(".accordionLink").click(function() {
var id = $(this).text();
// check if it is already active by checking for the existence of a class on the
//header
id = +id - 1;
if(!$("#sec_" + id).hasClass("ui-state-active")) {
$( "#accordionId" ).accordion('activate', id);
}
});
If your triggers are different than the accordion IDs, then you will have to use a mapping of triggers to accordion IDs.
精彩评论