Problem with .append() and jquery code

Problem with .append() and jquery code

Hi i have problem with the method .append()
With an ajax call i load some elements  with the .append() method in this way

  1. $('#notice').append('<div class="'+data[i][9]+'">');...........ecc..

and this works fine, than i add also two buttons:
  1. $('#notice').append('<a class="btn btn-success conf " title="'+data[i][9]+'">Conferma</a>');
  2. $('#notice').append('<a class="del btn btn-danger" id="'+data[i][9]+'">Elimina</a>  ');
The array data is not important.
As you can see this buttons has class ".del" and ".conf" the other. Now when i add the element with the append i try to use the buttons to make an action on a click but it doesn't works.
If i create the buttons without jquery like a normal html tag the function on click works.

Here the function:



  1. $(".del").click(function(){
  2. var del=$(this).attr('id');
  3. $.ajax({
  4. type: "POST",
  5. url: "../ajax/ajax-pren.php",
  6. cache: false,
  7. dataType: "json",
  8. data: {
  9. iddel: del
  10. },
  11. success: function (data) {
  12. if (data.error == false) {
  13. $("."+del).hide();
  14. }else{
  15. alert("error");
  16. }
  17. },
  18. error: function (e, t, n) {
  19. $('#notice').show();
  20. $("#notice").addClass("alert alert-danger");
  21. $("#notice").html('Qualcosa non va, chiamata ajax                                     fallita....'+t+'........'+n+'....');
  22. }
  23. });
  24. });

So how can i append an element to the dom and then execute a function on it?

Sorry for the bad english