Html
| The code is as follows |
Copy Code |
<p class= "Item" >
<input type= "text" Name= "meta_key[164]" value= "file1" size= "/><a" href= "/18" id= "164" class= "button Remove" >remove</a>
</p> |
Requirements Description:
Click the ' Remove ' link to delete the page element based on the Ajax return value.
Invalid method
| The code is as follows |
Copy Code |
$ ('. Remove '). Bind (' click ', function () {
$.ajax ({
Type: ' Post ',
url:$ (This). attr (' href '),
DataType: ' JSON ',
Data:{id: $ (this). attr (' id ')},
Success:function (msg) {
if (msg.error==0) {
alert (msg.msg);
}else{
$ (this). Parent (). remove ();//You cannot get the parental element here
}
}
});
return false;
}); |
Effective way to
| code is as follows |
copy code |
$ ('. Remove '). Bind (' click ', function () {
div=$ (this). parent ();///First get the parental element
$.ajax ({
Type: ' Post ',
url:$ (This). attr (' href '),
DataType: ' JSON ',
Data:{id: $ (this). attr (' id ')},
Success:function (msg) {
if (msg.error==0) {
alert (msg.msg);
}else{
Div.remove () and/or delete
}
}
});
return false;
}); |
Other similar problems can be solved by the same method