How To Increment jQuery Element ID

dryncattecy

New Member
I have instances of jPlayer (jquery audio player): jPlayer1, jPlayer2, jPlayer3, jPlayer4, each initialized and preloaded with audio files. Calling function below will traverse an existing array and adding the methods that plays the preloaded audio.\[code\]function addPlayAudioMethodToExerciseArray(){ for (i in qaArray){ qaArray.playAnswer = function(){ $('#jPlayer'+i).jPlayer('play',0);} }} \[/code\]It creates the method alright except for the part ('#jPlayer'+i) is not evaluated to become ('#jPlayer1'), ('#jPlayer2'), etc.Many thanks in advance.Note: I'm a noob.
 
Top