PHP- on click timing with dynamic id

I have a symbol thats generated with a dynamic id (‘#id’+key) and when i click it, something should happen. But how do i go through the keys because, when i need the keys to go trough to find out which symbol i clicked, i already must have started the keypress, and without the keys the keypress doesnt work, and if i try it the other way round, how should i trigger the keys going through before the actual event?
This is the way i currently wrote it.

Thanks in advance

Code:

   for(var key = 0; key < GlobalVarUS; key++){
         $('#ZFDialog'+key).off('click').on('click',function(){

    }); 
}


Source: stackoverflow-php