jbrooksuk Posted July 2, 2009 Share Posted July 2, 2009 Hey, I posted this tutorial on my blog. It describes the use of jQuery and how to add a row to a table. Hopefully this will be one in many tutorials. Feedback would be good, I did this in 10 minutes I had free whilst working. Helped me concentrate again. http://www.james-brooks.net/?p=281 James Link to comment https://www.neowin.net/forum/topic/792200-jquery-add-a-row-to-a-table/ Share on other sites More sharing options...
Kudos Veteran Posted July 2, 2009 Veteran Share Posted July 2, 2009 When hooking into anchor tags, you should be returning false to stop the default action of navigating to the location in the href, even if it's only a #. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Add Row example</title> <script src="dist/jquery.js" type="text/javascript"></script> <script type="text/javascript"> <!-- jQuery Code will go underneath this --> $(document).ready(function () { // Code between here will only run when the document is ready $("a[name=addRow]").click(function() { // Code between here will only run when the a link is clicked and has a name of addRow $("table#myTable tr:last").after('<tr><td>Row 4</td></tr>'); return false; }); }); </script> </head> <body> <table style="width: 100%" id="myTable"> <tr><td>Row 1</td></tr> <tr><td>Row 2</td></tr> <tr><td>Row 3</td></tr> </table> <a href="#" name="addRow">Add Row</a> </body> </html> Link to comment https://www.neowin.net/forum/topic/792200-jquery-add-a-row-to-a-table/#findComment-591223226 Share on other sites More sharing options...
jbrooksuk Posted July 2, 2009 Author Share Posted July 2, 2009 When hooking into anchor tags, you should be returning false to stop the default action of navigating to the location in the href, even if it's only a #. Yes you are correct. This is what happens when you don't have that much time. I shall add it when my network is working again. Link to comment https://www.neowin.net/forum/topic/792200-jquery-add-a-row-to-a-table/#findComment-591223344 Share on other sites More sharing options...
vebjorn Posted October 30, 2010 Share Posted October 30, 2010 Seems like your page has been moved.. Can you please update the link? Vebj?rn Hey, I posted this tutorial on my blog. It describes the use of jQuery and how to add a row to a table. Hopefully this will be one in many tutorials. Feedback would be good, I did this in 10 minutes I had free whilst working. Helped me concentrate again. http://www.james-brooks.net/?p=281 James Link to comment https://www.neowin.net/forum/topic/792200-jquery-add-a-row-to-a-table/#findComment-593321224 Share on other sites More sharing options...
Recommended Posts