I don't know why this working:
$('.deleteQuestion').live('click', function(){
$.ajax({
type: 'GET',
url: '/delete_question/' + $(this).attr('name') + '/',
success: $('[what="question"][name="' + $(this).attr('name') + '"]').remove()
});
});
but this not working:
$('.deleteQuestion').live('click', function(){
$.ajax({
type: 'GET',
url: '/delete_question/' + $(this).attr('name') + '/',
success: function(){$('[what="question"][name="' + $(this).attr('name') + '"]').remove();} }
});
});
Does someone know?
The success callback doesn't operate on the same this that the click handler does. Save it in a variable:
$('.deleteQuestion').live('click', function(){
var element = $(this);
$.ajax({
type: 'GET',
url: '/delete_question/' + $(this).attr('name') + '/',
success: function(){ //this has to be a function, not a jQuery chain.
$('[what="question"][name="' + element.attr('name') + '"]').remove();}
}
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With