Hi there,
First question ever asked at stackoverflow. So, problem is: Two accordion declarations on document.ready (jquery 1.4.2 and jquery ui 1.8.2):
$(document).ready(function () {
$("#accordion").accordion({
header: 'h3'
});
$("#accordion2").accordion({
header: 'h4'
});
$(function () {
$(".get-index").click(function () {
var activecontent = $("#accordion").accordion("option", "active");
alert(activecontent);
});
});
});
HTML:
<div id="accordion">
<h3><a href="#">Section 1</a></h3>
<div>
Content Section 1: Parent
<div id="accordion2">
<h4><a href="#">SubSection 1</a></h4>
<div>content section 1: child</div>
<h4><a href="#">SubSection 2</a></h4>
<div>content section 2: child</div>
<h4><a href="#">SubSection 3</a></h4>
<div>content section 3: child</div>
<h4><a href="#">SubSection 4</a></h4>
<div>content section 4: child</div>
</div>
</div>
<h3><a href="#">Section 2</a></h3>
<div>
Content Section 2: Parent
</div>
<h3><a href="#">Section 3</a></h3>
<div>
Content Section 3: Parent
</div>
<h3><a href="#">Section 4</a></h3>
<div>
Content Section 4: Parent
<button type="button" class="get-index ui-button ui-button-text-only ui-widget ui-state-default ui-corner-all">
<span class="ui-button-text">index</span>
</button>
</div>
</div>
And finally: what's wrong and why "activecontent" is 7? I know, that there are 4 parent panels + 4 child panels and starting from 0, it is 7. But I'm trying to get index of last parent panel and it should be 3.
Any help much appreciated.
Code posted: http://jsbin.com/eqewe