1

I don't english fine, sorry if i write bad here....

I used a foreach of php and within there is a label with a class called ..... and do make one click appear the index of element, how do it ?

For Example

   <? foreach($tipo_persona as $persona){ ?>
         <label id="lb_person" class="simulasublink"><? echo $persona["tipo"]; ?> </label><br>
    <? } ?>

i could use id="'.$i.'" with for($i = 0;$i <= ....).. for get an id but i want other way .. I had read something of each() in jquery but i haven't accomplished a fit for make good the that i want.

thank to all..

1 Answers1

0

in a fiddle http://jsfiddle.net/sosgenru/

$('.simulasublink').each(function(i) {
    $(this).on('click',function() {
        alert("this is the "+i+" element");
    });
});

Also don't use the same id in your labels it produces inaccurate code since id's are unique

 <? $i=0; foreach($tipo_persona as $persona){ ?>
         <label id="lb_person<? echo $i; ?>" class="simulasublink"><? echo $persona["tipo"]; ?> </label><br>
    <? $i++;} ?>