Dynamic Tables in JavaScript



I need a table that will expand and decrease in size as new items are added and or deleted.


Must be in JavaScript


You will need to make a place holder in the html file using the table tags and give it an id
<table id="myTable"></table>


Creating a button
var btn = document.createElement("INPUT");
btn.setAttribute("type", "button");
btn.setAttribute("value", "x");
btn.setAttribute("onclick", "aFunction(this)");

Remember you will have to navigate using dot notation to where the aFunction(this) is if it is contained within an object or accessed by going through an object.

Creating the table
var table = document.getElementById("myTable");
var row = table.insertRow(-1); // -1 will add new rows to the bottom.
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
var aPrice = document.getElementById("mealNames").innerHTML = “cell content”;

cell1.innerHTML = document.getElementById("mealNames").innerHTML = “cell content”;
cell2.innerHTML = “cell content”;



Popular posts from this blog

How to install Linux Kali 2016.1 into Parallels and install Parallels tools.

How to play spectrum games on a Mac, Windows or even GNU/Linux.

Build A Test Website In 3 Easy Steps