need to generate unlimited number of unique id's with jQuery

jquery

Solution

var id = 1;
$('.foo .bar').each(
   function() { 
     $(this).attr('id', 'id' + id++); 
});

In order to bind event listeners to these, you have to either do it in the loop or use `live`.

Problem

extreme n00b here... I've got a number of elements (dynamically generated by back end so it could be quite a few) and all need a unique id. I'm trying to work out how to do this wth jQuery and not doing so well. Any help is appreciated. In the code below, I'd want each "bar" div to get a unique id, like id1, id2 etc etc ``` <div class="foo"> <ul class="bar"> </ul> <ul class="bar"> </ul> <ul class="bar"> </ul> <ul class="bar"> </ul> </div> ```

Original source