jQuery: Hide Ajax Loaded Div After Additional Ajax Request
jQuery('.delete-tag').live('click', function(e) {
e.preventDefault();
var id = jQuery(this).attr('id');
var data_string = "ajax=1&tag-id=" + id + "";
jQuery.ajax({
type: "POST",
url: file_path + "tags/edit/delete/",
data: dat开发者_C百科a_string,
dataType: "json",
success: function(ajax_output) {
jQuery(this).hide();
}
});
});
The .delete-tag
link is loaded via ajax in a modal window. I use live()
to bind the click event for this link. Ajax runs ok, but I can't get the hide()
to work on the ajax loaded link.
Suggestions? Everything works except the hiding.
Once inside the ajax success function, the this
points to a different object. Store the origional reference in another variable:
var orig = jQuery(this);
jQuery.ajax({
type: "POST",
url: file_path + "tags/edit/delete/",
data: data_string,
dataType: "json",
success: function(ajax_output) {
orig.hide();
}
});
精彩评论