In my .js file I have a button listener that generates following:

```
$('#add').click(function(){
$('<div id="school-field'+i+'"><fieldset><a href="javascript:" id="remove'+i+'">Remove</a></fieldset></div>').fadeIn('slow').appendTo('.school');
});

```

I've been trying to generated listeners to added buttons but I can't get it to work.
I tried to use delegate on 'a' but than it's problem to find div's id. If I have the same div id for all of the generates (div id="school-field"), I do make it work but it deletes the last added elements, not the one where "remove'+i+'" was clicked. 
I also tried to define a listener inside it by doing, but it throws exception:

```
$('#remove'+i'').click(function(){
var div = document.getElementById("school-field'+i+'");
div.parentNode.removeChild(div);
});

```

How can I get it to work properly?