Question

I've created a jQuery accordion for my website, it all works very fine. But now I want to have some javascript executed when i click on a link of the accordion. In the jQuery documentation I found this solution:

        $('ul.accordion').accordion().bind("accordionchange", function(event, something, ui) {
            alert('ALLO');
        });

Which should execute everytime the accordion changes, but untill now... no results (no alert when I click on an accordion link. Does anyone have good tips on how to do this?

Was it helpful?

Solution

Your issue is your trying to chain the bind to the accordion

You can create it when you initialize the accordion - Demo here

$('ul.accordion').accordion( {
   change : yourFunction 
});

function yourFunction() {
   //we hate alerts, use console
   console.log('console rocks');
}

Or later after you have already created the accordion

$('ul.accordion').accordion();

$('ul.accordion').bind('accordionchange', yourFunction);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top