The reason its returning undefined
is because you're trying to extract an href
attribute value that doesn't exist because this
refers to the #accordian
div.
You can do this by getting the link without the class collapsed
:
$('#accordion').on('show.bs.collapse', function () {
//get the anchor of the accordian that does not has the class "collapsed"
var openAnchor = $(this).find('a[data-toggle=collapse]:not(.collapsed)');
//extract the href
var sectionID = openAnchor.attr('href');
console.log(sectionID);
});