Setting up click function does not work in a for loop
I'm using jQuery for some time now. There is a problem I cannot resolve
The following is working fine
$( '#mehrUnsereKunden' ).click(function ( ) { setzeAuf ( this.id, 'myUnsereKunden' ) ; });
$( '#mehrUnternehmen' ).click(function ( ) { setzeAuf ( this.id, 'myUnternehmen' ) ; });
$( '#mehrWasWirBieten' ).click(function ( ) { setzeAuf ( this.id, 'myWasWirBieten' ) ; });
If I write this as a for loop, it does not work anymore
var kapitelListe = new Array (
"WasWirBieten",
"UnsereKunden",
"Unternehmen" );
for ( var idx = 0; idx < kapitelListe.length; idx++ ) {
$( '#mehr' + kapitelListe[idx] ).click(function ( ) { setzeAuf ( this.id, 'my' + kapitelListe[idx] ) ; });
}
It would be simpler for programming to work with the list (adding or deleting parts, or even generating the list in PHP).
The part " '#mehr' + kapitelListe[idx] " is working fine
The part " 'my' + kapitelListe[idx]" does not work (it says "myundefined").
Can somebody help?