Hi i have problem with the method .append()
With an ajax call i load
some elements with the .append() method in this way
- $('#notice').append('<div class="'+data[i][9]+'">');...........ecc..
and this works fine, than i add also two buttons:
- $('#notice').append('<a
class="btn btn-success conf " title="'+data[i][9]+'">Conferma</a>');
- $('#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:
- $(".del").click(function(){
-
var del=$(this).attr('id');
-
$.ajax({
-
type: "POST",
-
url: "../ajax/ajax-pren.php",
-
cache: false,
-
dataType: "json",
-
data: {
-
iddel: del
-
},
-
success: function (data) {
-
if (data.error == false) {
-
$("."+del).hide();
-
}else{
-
alert("error");
-
}
-
},
-
error: function (e, t, n) {
-
$('#notice').show();
-
$("#notice").addClass("alert alert-danger");
-
$("#notice").html('Qualcosa non va, chiamata
ajax fallita....'+t+'........'+n+'....');
-
}
-
});
-
});
So how can i append an element to the dom and then execute a
function on it?
Sorry for the bad english