The Document Object Model (DOM) is a programming interface for
web documents. It represents the page so that programs can
change the document structure, style, and content.
The DOM represents the document as nodes and objects; that way,
programming languages can interact with the page.
A web page is a document that can be either displayed in the
browser window or as the HTML source. In both cases, it is the
same document but the Document Object Model (DOM) representation
allows it to be manipulated. As an object-oriented
representation of the web page, it can be modified with a
scripting language such as JavaScript.
The Document Object Model (DOM) is a programming interface for web documents.
It represents the page so that programs can change the document structure,
style, and content. The DOM represents the document as nodes and objects;
that way, programming languages can interact with the page.
var myData = [{user: "James", address: "123 Keele St. Toronto, ON.", email:"james12@myseneca.ca"},
{user: "Mary", address: "92 Appleby Ave. Hamilton, ON.", email:"mary356@myseneca.ca"},
{user: "Paul", address: "70 The Pond Rd. North Youk, ON.", email:"paul345@myseneca.ca"},
{user: "Catherine", address: "1121 New St. Burlington, ON.", email:"catherine89@myseneca.ca"}];
window.onload = function() {
document.querySelector("#button1").onclick = generateTable;
}
function generateTable(){
var tbl = document.querySelector("#outputTable");
var tblExistingBody = tbl.querySelector("tbody");
if (tblExistingBody) tbl.removeChild(tblExistingBody);
var tblBody = document.createElement("tbody");
for (var i = 0; i < myData.length; i++) {
var row = document.createElement("tr");
row.appendChild(getTdElement(myData[i].user));
row.appendChild(getTdElement(myData[i].address));
row.appendChild(getTdLinkElement(myData[i].email, myData[i].email));
tblBody.appendChild(row);
}
tbl.appendChild(tblBody);
}
function getTdElement(text) {
var cell = document.createElement("td");
var cellText = document.createTextNode(text);
cell.appendChild(cellText);
return cell;
}
function getTdLinkElement(text, href) {
var anchor = document.createElement("a");
anchor.setAttribute("href", "mailto:"+href);
var anchorText = document.createTextNode(text);
anchor.appendChild(anchorText);
var cell = document.createElement("td");
cell.appendChild(anchor);
return cell;
}