Question: Im creating the same button in a loop as long as there is a certain condition, and I want to run the same jquery event handler for those buttons.

The problem is that the event handler only works for the first button generated.

My button is generated like this:

```
<?php while($row_c= mysqli_fetch_array($result_comments))
{ ?>
<button name="comment" id="comment" class="button_comment" value="Post">Post</button>
<?php } ?>

```

and the jquery im using is this:

```
$('.button_comment').click(function()
{
    //some staff thats done here
});

```

What should do, so that the event handler works for all buttons that are generated?
Thank you

Answer: 
Your jQuery should work. Note that your buttons form invalid HTML/DOM: The `id` on an element [**must** be unique](http://www.w3.org/TR/html5/dom.html#the-id-attribute). But since you're also using a class (which doesn't have to be unique), and that's what you're using in your jQuery selector, that works: [Live Example](http://jsbin.com/ubiWEvi/1) | [Source](http://jsbin.com/ubiWEvi/1/edit)

Perhaps when you were trying it and it wasn't working, you were using `$("#comment").click(...)`, which would *not* work, because of the `id` issue.
Take the ID off from your php code. Remember ID's should be unique elements. Also, change your jquery from:

```
('.button_comment').click(function()
{
    //some staff thats done here
});

```

to 

```
('.button_comment').on('click', function()
{
    //some staff thats done here 
});

```

The on event will perform what you tell it to do at the time you tell it to do, so it does it pretty much at runtime. If you use your previous code, the element must exist at page load time for it to work.