In the callback function "OnSuccess",i can't get the element which i've clicked. After click the "Del" button ,i try to remove the "tr" element which one the "Del" button in that i just clicked.how to do this?
Asked
Active
Viewed 1,121 times
1

hutchonoid
- 32,982
- 15
- 99
- 104

developer.zheng
- 11
- 3
-
I knew that $(selector).remove() could remove the DOM elements,but i just wanted remove it in the Callback function. Note: not jquery ajax or get,post ,just asp.net mvc @Ajax generated with unobrusive-ajax,in that OnSuccess callback function. – developer.zheng Aug 18 '15 at 14:57
-
Such as : @Ajax.Actionlink("Del","actionName",new AjaxOption({OnSuccess="SuccessCallback"}) – developer.zheng Aug 18 '15 at 15:00
2 Answers
1
You can remove it using jquery:
$('#selector').remove();
also check this out:
0
I use a combination of $(this)
to get the button (or other dom element that triggered it).
Then .closest
with the tr
parameter to get the row.
Followed by .remove
to remove it:
$(this).closest('tr').remove();

hutchonoid
- 32,982
- 15
- 99
- 104
-
I knew that could remove it ,but i wanna to remove it in the callback function of OnSuccess for the unobtrusive-ajax. – developer.zheng Aug 19 '15 at 07:08
-
@developer.zheng Sorry, a quick way I can think of is to pass the id across to the action. Return it as data and if you add a parameter to your `OnSuccess` call i.e. `OnSuccess(e)` the returned data will be available. Failing that I would need to setup a test example to debug and see if I could navigate to the event. You have included no code in your example though. – hutchonoid Aug 19 '15 at 09:06