Delete row table using jQuery
jquery
Solution
You don't need to call preventDefault(). Simply returning false from the event handler has the same effect.
To remove the row where the `<a>` link is located, you can call $(this).closest("tr").remove():
$(document).ready(function() {
$("a").click(function(event) {
alert("As you can see, the link no longer took you to jquery.com");
var href = $(this).attr('href');
alert(href);
$(this).closest("tr").remove(); // remove row
return false; // prevents default behavior
});
);
Problem
Suppose I have a table like this ``` id name address action -------------------------------------- s1 n1 a1 delete s2 n2 a2 delete ``` Delete is a link for example `<a href="http://localhost/student/delete/1">`. In the real case I delete the student using ajax. In order to simplify the code, I just alert the link and omit the ajax script. I just wanna know How to delete row from the html document using jquery. ``` $(document).ready(function() { $("a").click(function(event) { alert("As you can see, the link no longer took you to jquery.com"); var href = $(this).attr('href'); alert(href); event.preventDefault(); }); ); ``` I want, After I alert the link the selected row will be remove automatically. Is there any suggestion how to implement this one ?