views:

612

answers:

1

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?

+1  A: 

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);
redsquare
Thanx for your tips, OK I hate alerts too ;-) I'll try using this console stuff from now on! But the suggestions you are making are not working out for me, in the console (firebug) the tekst 'console rocks' only prints once... on page load. Not when I click on one of the accordion links. I tried both of your suggestions. This code is within the $(document).ready block in my HTML HEAD.
tvgemert
OK, turns out I was using another accordion script. When I try your solution with the current official accordion (from: http://docs.jquery.com/UI/API/1.7.1/Accordion) it works. It took me some time to wrap my head around the nature of jQuery and to get it working.
tvgemert