I have problem with remove() method. I can’t remove $(this) object. My code is:
$(".submit_add_type").live("click", function() {
var parent = $(this).parent();
var type_value = parent.children('.type_value').val();
var type_name = parent.children('.type_name').val();
var parent2 = parent.parent();
var permission = parent2.attr('id').replace('perm_types_', '');
$.ajax({
url: "/admin/ajax/permission_type_add", type: "POST", cache: false,
data: {
permission: permission,
type_value: type_value,
type_name: type_name,
},
success: function(text) {
if(text.substr(0,2) == "ok") {
var id = text.replace('ok|', '');
$(this).remove();
parent.append('<input class="submit" type="submit" name="" value="edytuj" id="edit_type_'+ id +'" /> <input class="submit delete_type" type="submit" name="" value="usuń" id="delete_type_'+ id +'" />')
} else {
alert(text);
}
}
});
});
When I change $(this).remove(); on $(".submit_add_type").remove(); it works perfectly. What could be wrong?
The thing is, there can be other objects with this submit_add_type class and I want to remove only a particular one.
Upon entering the
successfunction,$(this)becomes thetextargument. Change it to something like: