HTML DOM
JavaScript
// This is a DOM interface with JAVASCRIPT by using JSON data
// Creating Table with DOM objects
var myData = [{user: "James", address: "123 Keele St. Toronto, ON.", email:"[email protected]"},
{user: "Mary", address: "92 Appleby Ave. Hamilton, ON.", email:"[email protected]"},
{user: "Paul", address: "70 The Pond Rd. North Youk, ON.", email:"[email protected]"},
{user: "Catherine", address: "1121 New St. Burlington, ON.", email:"[email protected]"}];
window.onload = function() {
document.querySelector("#button1").onclick = generateTable;
}
function generateTable(){
// get the reference for the body
var tbl = document.querySelector("#outputTable");
// revove existing Body element
var tblExistingBody = tbl.querySelector("tbody");
if (tblExistingBody) tbl.removeChild(tblExistingBody);
// creates a <tbody> element
var tblBody = document.createElement("tbody");
// creating all table rows
for (var i = 0; i < myData.length; i++) {
// creates a table row
var row = document.createElement("tr");
// Create a <td> element and put them at the end of the table row
row.appendChild(getTdElement(myData[i].user));
row.appendChild(getTdElement(myData[i].address));
row.appendChild(getTdLinkElement(myData[i].email, myData[i].email));
// add the row to the end of the table body
tblBody.appendChild(row);
}
// put the <tbody> in the <table>
tbl.appendChild(tblBody);
}
// Create a <td> element and a text
function getTdElement(text) {
var cell = document.createElement("td");
var cellText = document.createTextNode(text);
cell.appendChild(cellText);
return cell;
}
// Create a <td> element with a hyperlink
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;
}
<!-- USING EVENT HANDLER FOR DOM HTML -->
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>WEB222</title>
<style>
body { margin: 0 18%; }
</style>
<script>
window.onload = function() { // why use window.onload?
var elem = document.querySelector("#myBtn");
elem.addEventListener( "click", displayDate );
}
function displayDate() {
document.querySelector("#demo").innerHTML = (new Date()).toLocaleString();
}
</script>
</head>
<body>
<h1>WEB222 - HTML DOM Event</h1>
<p>Click "Show Current Time" to execute the displayDate() function.</p>
<p id="demo"></p>
<button id="myBtn">Show Current Time</button>
<br>
<!-- for downloading source files -->
<p><a href="" Download>Download</a></p>
</body>
</html>
Also in JavaScript:
- Title
- how to make dynamic columns in jquery
- Category
- JavaScript
- Title
- dropzone upload only two files
- Category
- JavaScript
- Title
- funciones invocan a funciones javascript
- Category
- JavaScript
- Title
- facebook integration in node.js
- Category
- JavaScript
- Title
- how to use js console log
- Category
- JavaScript
- Title
- angular right click on link
- Category
- JavaScript
- Title
- gsap
- Category
- JavaScript
- Title
- bot discord comment récupérer la pdp de quelqu'un
- Category
- JavaScript
- Title
- isogram
- Category
- JavaScript
- Title
- angular generate component
- Category
- JavaScript
- Title
- how to add validator to formgroup
- Category
- JavaScript
- Title
- javascript access pushed element
- Category
- JavaScript
- Title
- hashing in javascript
- Category
- JavaScript
- Title
- array.splice javascript
- Category
- JavaScript
- Title
- how to add array numbers in javascript
- Category
- JavaScript
- Title
- angular sumar labels
- Category
- JavaScript
- Title
- convert string to char array javascript
- Category
- JavaScript
- Title
- color js
- Category
- JavaScript
- Title
- change width in js
- Category
- JavaScript
- Title
- data-widget="pushmenu" collable automatically
- Category
- JavaScript
- Title
- ajax laravel example
- Category
- JavaScript
- Title
- get value of hidden field jquery
- Category
- JavaScript
- Title
- ISS proxy express
- Category
- JavaScript
- Title
- add dynamic value to id attribute in angular 8
- Category
- JavaScript
- Title
- express bodyparser deprecated
- Category
- JavaScript
- Title
- how to get the size of the window in javascript
- Category
- JavaScript
- Title
- add a slash to string in javascript
- Category
- JavaScript
- Title
- debug node
- Category
- JavaScript
- Title
- bind and unbind jquery validation
- Category
- JavaScript
- Title
- express get url parameters
- Category
- JavaScript
- Title
- forever loop in js
- Category
- JavaScript
- Title
- get day js
- Category
- JavaScript
- Title
- creating js objects
- Category
- JavaScript
- Title
- edje js not pre compile for node 12 version
- Category
- JavaScript
- Title
- add elements to an array with splice
- Category
- JavaScript
- Title
- angular bootstrap not working
- Category
- JavaScript
- Title
- how the concat function works javascript
- Category
- JavaScript
- Title
- array.unshift in javascript
- Category
- JavaScript
- Title
- change value of drop down using jquery
- Category
- JavaScript
- Title
- declare multiple variables javascript
- Category
- JavaScript
- Title
- convert json to object jackson
- Category
- JavaScript
- Title
- function js
- Category
- JavaScript
- Title
- how to get data from localstorage in javascript
- Category
- JavaScript
- Title
- convert json to csv npm
- Category
- JavaScript
- Title
- input set variable angular
- Category
- JavaScript
- Title
- graphql yoga access http headers
- Category
- JavaScript
- Title
- how to get a random element of an array javascript
- Category
- JavaScript
- Title
- javascript array concat spread operator
- Category
- JavaScript
- Title
- clear terminal node js
- Category
- JavaScript
- Title
- discord.js how to go back a file
- Category
- JavaScript
- Title
- how to add text to h2 with jquery
- Category
- JavaScript
- Title
- angular size of array
- Category
- JavaScript
- Title
- how to remove an class in javascript
- Category
- JavaScript
- Title
- contains substring javascript
- Category
- JavaScript
- Title
- get date now javascript
- Category
- JavaScript
- Title
- how to add border to a text in html with javascript
- Category
- JavaScript
- Title
- javascript add text to textarea overwrite
- Category
- JavaScript
- Title
- create a form and submit it dynamically jquery
- Category
- JavaScript
- Title
- get selected option value
- Category
- JavaScript
- Title
- get current directory vbscript
- Category
- JavaScript
- Title
- how to delete an element of an array in javascript
- Category
- JavaScript
- Title
- angular calendar updating until hovering
- Category
- JavaScript
- Title
- angular npm angular material
- Category
- JavaScript
- Title
- ionic cordova icon notification
- Category
- JavaScript
- Title
- generate new component angular
- Category
- JavaScript
- Title
- javascript ajax request
- Category
- JavaScript
- Title
- angular one way property binding
- Category
- JavaScript
- Title
- angular moment pipe timeAgo
- Category
- JavaScript
- Title
- how to push multiple data to different parents in a single request in firebase
- Category
- JavaScript
- Title
- bq show pretty json
- Category
- JavaScript
- Title
- console.log in jsx
- Category
- JavaScript
- Title
- html hide till button click
- Category
- JavaScript
- Title
- how to find unique elements in array in javascript
- Category
- JavaScript
- Title
- document delete element
- Category
- JavaScript
- Title
- compare string by several strings js
- Category
- JavaScript
- Title
- document queryselectorall and map javacript
- Category
- JavaScript
- Title
- angular submit form programmatically
- Category
- JavaScript
- Title
- how to define cardTitle background image in mdl in reactjs
- Category
- JavaScript
- Title
- express get query params from url
- Category
- JavaScript
- Title
- fix your timestep javascript
- Category
- JavaScript
- Title
- Angular material design
- Category
- JavaScript
- Title
- how the filter() function works javascript
- Category
- JavaScript
- Title
- go to another page using javascript
- Category
- JavaScript
- Title
- how to append select option in jquery
- Category
- JavaScript
- Title
- auto refresh page javascript
- Category
- JavaScript
- Title
- how to clear radio field in jquery
- Category
- JavaScript
- Title
- can we import jquery library from developer tools
- Category
- JavaScript
- Title
- get current screen name react navigation
- Category
- JavaScript
- Title
- check array values equal js
- Category
- JavaScript
- Title
- how to extract values from array in javascript
- Category
- JavaScript
- Title
- iframe loader jquery
- Category
- JavaScript
- Title
- delete last element of array js
- Category
- JavaScript
- Title
- how to make @click in router-link vuejs
- Category
- JavaScript
- Title
- enable disable click on div jquery
- Category
- JavaScript
- Title
- convert number to k m b javascript
- Category
- JavaScript
- Title
- how to get a user input in js
- Category
- JavaScript
- Title
- angular two datepickers
- Category
- JavaScript
- Title
- how to use custom stylesheets express node
- Category
- JavaScript
- Title
- ionic (Emitted value instead of an instance of Error
- Category
- JavaScript
- Title
- how to limit input type max length
- Category
- JavaScript