Question: I am creating some stuff on a `.on()` jquery handler like that

```
$('#idhere').on('click', function(){
   //create a couple of divs with a class
   });

```

Now I also want to add an event on the divs created, I have tried:

```
$('.divcreated').bind('mouseover', function(){
   //do some magic
   });

```

For some reason the second event is never triggered probably because they are both asynchronous. Any ideas to trigger the second event?

Answer: 
Assuming that `X` is the type of the objects in the list, then you can do something like this:

```
void DoSomething(X& object) {
  object.count, object.avg;
}
void DoSomethingElse(int& count, int& average) {
  ...
}

int main() {
   ...
   for(std::list<X>::iterator it=myList.begin(), end=myList.end(); it != end; ++it) {
     DoSomething(*it); // how I'd do it
     DoSomethingElse(it->count, it->avg); // Equally valid way that you did it
   }
   ...
}

```

Just remember:

* `container.begin()` is the a pointer to the first element
* `container.end()` is a pointer to one-past-the-last element
* `*it` is a reference to the pointed-to element
* `it != container.end()` is how you tell if you are at the end
* `it->x` is a member of the pointed-to element
* removing an object from a container might invalidate outstanding iterators, depending upon several factors.
* `++it` is probably more efficient than `it++`

---

**EDIT**: OP asks:

> 
> 
> > 
> > I'm not iterating through the list and running calc\_average on every single node, but rather iterating through the list looking for a specific item value. Once I find the one of interest, I'm calling the calc\_average function on that specific node. I just don't need to have the for loop. Instead I would arrive at my desired iterator, and pass that via \*it to void DoSomething ?
> > 
> > 
> > 
> 
> 
> 

I think you understand how it works now. You'd have some code to search for the indicated node, and then some other code to invoke your function:

```
   std::list<X>::iterator it, end;
   for(it=myList.begin(), end=myList.end(); it != end; ++it) {
     // Look for the special node:
     if( it->magicValue == 42 ) {
       // We found it!
       break;
     }
   }

    // Either it is equal to end (boo!) or it points to the special node (yay!)
   if( it == end ) {
      std::cerr << "Could not find special node!\n";
   }
   if( it != end ) {
      DoSomething(*it);
   }

```
I am currently working with dynamic content and I found
I have a SPRITE structure
std::list characters\_spr;
I declare a character by SPRITE character then I use

```
characters_spr.push_back(character)

```

then
I use a for loop to iterate over the list

```
for(SPRITE &character : characters_spr){
   somefunction(character, ....);
}

```

in the somefunction I have
somefunction(SPRITE &spr, ......................)

and when the somefunction is called it updates the character data for the character within the list.