JS Simple table add row and delete Row Operation example

Source: Internet
Author: User
Tags bind tagname

  This article mainly introduces the JS simple table add row and delete line operations, the need for friends can refer to the following

  Code as follows: <html>  <head>  <script src= "Http://code.jquery.com/jquery-1.11.0.min.js" > </script>  <script> //Create an HTML element   function $c (tagname) {  return Document.createelement (tagname); } //document to be executed after loading   $ (document). Ready (function () { // The Click event   $ ("#addrow") of the Bind Add Row button. Bind ("click", Function () { //Get table  var tab = $ ("#tab"); //Create TR Elements & nbsp var tr = $c ("tr"); //+ for table append TR element   Tab.append (TR); //create TD element   VAR td1= $c ("TD"); //TD element Content &NB Sp Td1.innerhtml= "Insert1"; //Add TD Element   Tr.appendchild (TD1);  var td2= $c ("TD") to the newly appended TR;  Td2.innerhtml= "Insert2";  tr.appendchild (TD2); }); //Bind click event   $ ("#deleterow") to delete Row buttons. Bind (" Click, function () { //Get first line of table   var tab = $ ("#tab tr:eq (0)"); //delete this row   Tab.remove (); }); &n Bsp });  </script>  </head>  <body>  <table border= '1 ' id= ' tab ' >  <tr>  <td>123</td>  <td>456</td>  </tr>   </table>  </br>  <button id= "AddRow" > Add line </button>  <button id= " DeleteRow "> Delete line </button>  </body>  </html>   

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.