When I want to delete the DOM element with jquery after confirming with alertifyJS it gives me the following error: Can not read property 'parents' of undefined I think it has to do something with the context this
, I have tried other things and everything is fine, but when I try to erase the element that triggered the action I can not.
I have saved in a variable the object that triggers the function and then try to call it inside but it does not work for me.
containerEventos.on('click','a.deleteAlimento',function(e){
e.preventDefault();
var deleteTrigger = $(this);
var nombreAlimentoBorrado =
deleteTrigger.parents('.headAlimento').find('.nombreAlimento').text();
alertify.confirm('Borrar: ' + nombreAlimentoBorrado , function(e){
if (e) {
deleteTrigger.parents('.fullAlimento').remove();
}
});
});
Something curious is that the function does recognize the context when adding the following:
.set('labels', {ok:'Alright!', cancel:'Naa!'})
But I do not change the labels for which I want to change and I left the following error in console:
Uncaught TypeError: alertify.confirm (...). set is not a function
containerEventos.on('click','a.deleteAlimento',function(e){
e.preventDefault();
var deleteTrigger = $(this);
var nombreAlimentoBorrado =
deleteTrigger.parents('.headAlimento').find('.nombreAlimento').text();
alertify.confirm('Borrar: ' + nombreAlimentoBorrado , function(e){
if (e) {
deleteTrigger.parents('.fullAlimento').remove();
}
}).set('labels', {ok:'Alright!', cancel:'Naa!'});
});