Delete all table rows except first one using jQuery.
HTML Code :
<!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery-git.js"></script> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>Delete all table rows except first one using jQuery.</title> </head> <body> <table border="1" id="myTable"> <tr> <th>Year</th> <th>Savings</th> </tr> <tr> <td>2014</td> <td>$10000</td> </tr> <tr> <td>2015</td> <td>$8000</td> </tr> <tr> <td>2016</td> <td>$9000</td> </tr> </table> <p> <input id="button1" type="button" value="Click to remove all rows except first one"/></p> </body> </html>
JavaScript Code:
$(document).ready(function(){ $('#button1').click(function(){ $("#myTable").find("tr:gt(0)").remove(); }); });
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
HTML Code :
JavaScript Code: