[英]jQuery help remove div after append
I have some problem with jQuery, won't to remove div after is created...here is the code 我的jQuery有问题,创建后不会删除div ...这是代码
$('.del').on('click', function() {
//delItem = $(this);
var data_id = $(this).attr('rel');
$.post('index/xhrDelete', {'data_id': data_id}, function(o) {
//delItem.parent().remove(); // i have tried this too
$(this).parent().remove();
}, 'json');
return false;
});
it removes div but when i refresh manually...but i want to be without refreshing the page here is html.... 它删除了div,但是当我手动刷新时...但是我希望不刷新页面,这里是html ....
<div>
ccc
<a class="del" href="#" rel="5">X</a>
</div>
<div>
test
<a class="del" href="#" rel="21">X</a>
testd X 经过测试的X
Give a shot with this : 试一下:
$('.del').on('click', function(e) { // Notice the 'e' in the function
$this = $(e.target); // Use it to retrieve the element that fired the event and turn it into a jQuery object
var data_id = $(this).attr('rel');
$.post('index/xhrDelete', {'data_id': data_id}, function(o) {
$this.parent().remove(); // You just need to remove its parent
}, 'json');
return false;
});
Try this out... 试试看...
$('.del').on('click', function() {
var self=this;
var data_id = $(self).attr('rel');
$.post('index/xhrDelete', {'data_id': data_id}, function(o) {
//delItem.parent().remove(); // i have tried this too
$(self).parent().remove();
}, 'json');
return false;
});
Hope it helps.... 希望能帮助到你....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.