Hi wyo,

Unless you need the unique ID for each paragraph, it might be easier
to bind the click by the class name. jQuery will perform the foreach
logic for you.

... your PHP code ... then in the head of your document ...

$(function(){ // wait until the document is ready
   $(".folder").click(function(){
      ... do your stuff ...
   });
});

However, your method of doing it should work as well. It could simply
be that with your code you are not waiting until the document is
ready.

Brian


On Apr 21, 3:51 am, wyo <[EMAIL PROTECTED]> wrote:
> I've a dynamically created array
>
>       var folders = new Array();
>       folders = <?PHP echo $json->encode ($folders) ?>;
>
> and html created with
>
>         foreach ($folders as $key => $d) {
>           echo "<p id=\"f$key\" class=\"folder\">$d</p>";
>         }
>
> and would like to bind a click handler to each element like
>
>       for (var i in folders) {
>         $('#f'+i).bind('click', function() {
>             ...
>         });
>       }
>
> yet the "$('#f'+i)" seems to be wrong. Any idea how to do that?
>
> O. Wyss

Reply via email to