I created a scrip with some help of stackoverflow.
At the moment my Code looks like
<script type="text/javascript">
$(function() {
$( "#accordion" ).accordion();
var hashId = 0,
$accordion = $('#accordion');
if (window.location.hash) {
$accordion.children('h3').each(function(i){
var txt = $(this).text().toLowerCase().replace(/\s+/g,'_');
this.id = txt;
if (txt === window.location.hash.slice(1)) {
hashId = i;
}
});
}
$accordion.accordion({
active: hashId,
animate: true,
heightStyle: 'content',
collapsible: true,
create: function( event, ui ) {
$accordion.children('h3').each(function(i){
$(this).before('<a class="accordion-link link" data-index="' + i + '" href="#' + this.id + '"></a>');
});
$accordion.find('.accordion-link').click(function(){
$accordion.accordion( "option", "active", $(this).data('index') );
});
}
});
});
</script>
The only question I've got, how can i close the first Accordion by default?
The HTML:
<div id="accordion">
<h3><a href="#link1">Link1</a></h3>
<div>content</div>
<h3><a href="#link2">Link2</a></h3>
<div>content</div>
</div>
Thanks, Chris
UPDATE
I deleted now the third line - the Code looks like:
<script type="text/javascript">
$(function() {
var hashId = 0,
$accordion = $('#accordion');
if (window.location.hash) {
$accordion.children('h3').each(function(i){
var txt = $(this).text().toLowerCase().replace(/\s+/g,'_');
this.id = txt;
if (txt === window.location.hash.slice(1)) {
hashId = i;
}
});
}
$accordion.accordion({
active: hashId,
animate: true,
heightStyle: 'content',
collapsible: true,
create: function( event, ui ) {
$accordion.children('h3').each(function(i){
$(this).before('<a class="accordion-link link" data-index="' + i + '" href="#' + this.id + '"></a>');
});
$accordion.find('.accordion-link').click(function(){
$accordion.accordion( "option", "active", $(this).data('index') );
});
}
});
});
</script>