JSFiddle - React, Tailwind, and code Playground

by 林 羿緯

HTML

<table id="testTable" cellpadding="10" border='1'>
  <tr>
    <td>1</td>
    <td>2</td>
    <td>3</td>
    <td>4</td>
  </tr>
  <tr>
    <td>
      <input type="button" id="add" value="+">
    </td>
  </tr>
</table>

CSS

table {
  border: 3px #cccccc solid;
}

td{
  width: 20px;
}

JavaScript

var index = 5;


$(function(){
  $(document).on("click","#add",(function(){
  	if(index % 4 == 0 ){
 			$("#add").parent().parent().prepend("</tr><tr>");
    }
    $("#add").parent().before("<td>"+index+"</td>")
    index++;
  }));
});