Reputation: 1783
I want to remove respective row on click "Remove" anchor tag.
From server response i am getting 1 but when i am trying to remove the parent of parent of anchor tag that is not working.
Here is code
As My Html code is:
<tr>
<td><?php echo $w_value['pro_name']; ?></td>
<td><?php echo $w_value['sellingprice']; ?></td>
<td><a class="remove_wishlist" href="javascript:;" data-uid="<?php echo $uid;?>" data-pid="<?php echo $w_value['id']; ?>">Remove</td>
</tr>
And My Ajax Code Is:
jQuery(document).on("click",".remove_wishlist",function(){
if(confirm('Are you sure to remove this item.')){
var pid = jQuery(this).data("pid");
var uid = jQuery(this).data("uid");
var urll = WEBSITE_URL+"pages/removewishlist";
var $this = $(this);
$.ajax({
type:'post',
url:urll,
data:{pid:pid,uid:uid},
success:function(data){
console.log(data);
if(data == 1){
$this.parent().parent("tr").remove();//this is not removing the entire row
}
}
});
}
});
Upvotes: 2
Views: 877
Reputation: 13344
You can use parents()
instead to traverse back up to parent matching <tr>
selector. Function .parent()
will only go one level up the DOM tree, whereas .parents()
returns a full collection of parents to traverse.
$this.parents("tr").remove();
Two less likely scenarios:
You may need to reference jQuery
specifically (and not using $
) like you do elsewhere in the codeblock:
var $this = jQuery(this); // was: $(this)
It might be that your data coming back is not expected format (integer) and so you could try comparison to string '1'
(maybe you've already tested this, and it's already working the way you write it, comparing data
as type integer
):
if( data == '1' ){ //....
Upvotes: 1