0
我想用class dialogBody清空div的内容,然后追加返回的ajax响应。请参阅下面的代码。我遇到的问题是.html(响应)不会执行任何操作,因为单击的元素将被删除。点击元素被移除后,如何继承$ this.closest('。dialogBody')的目标元素?jquery这个选择器被点击元素删除后
<div class="dialogBody">
<p>Some content<a href="/question/33" class="ajaxReplace">Click to show question</a></p>
</div>
<script>
$(".ajaxReplace").live("click", function(e){
e.preventDefault();
var $this = $(this);
$this.closest('.dialogBody').empty();
ajaxUrl = $(this).attr("href")+"?ajax=1";
$.ajax({
type: "POST",
url: ajaxUrl,
success: function(response){
$this.closest('.dialogBody').html(response);
console.log(response);
}
})
});
</script>