<html>
<head>
<title>Sample code - Traversing an HTML Table with JavaScript and DOM Interfaces</title>
<script>
function start() {
// get the reference for the body
var mybody = document.getElementsByTagName("body")[0];
// creates a <table> element and a <tbody> element
mytable = document.createElement("table");
mytablebody = document.createElement("tbody");
// creating all cells
for(var j = 0; j < 2; j++) {
// creates a <tr> element
mycurrent_row = document.createElement("tr");
for(var i = 0; i < 2; i++) {
// creates a <td> element
mycurrent_cell = document.createElement("td");
// creates a text node
currenttext = document.createTextNode("cell is row "+j+", column "+i);
// appends the text node we created into the cell <td>
mycurrent_cell.appendChild(currenttext);
// appends the cell <td> into the row <tr>
mycurrent_row.appendChild(mycurrent_cell);
}
// appends the row <tr> into <tbody>
mytablebody.appendChild(mycurrent_row);
}
// appends <tbody> into <table>
mytable.appendChild(mytablebody);
// appends <table> into <body>
mybody.appendChild(mytable);
// sets the border attribute of mytable to 2;
mytable.setAttribute("border", "2");
}
</script>
</head>
<body onload="start()">
</body>
</html>
Smilar Posts of javascript
-
Repair using javascript browser problem
Original: http://www.noupe.com/css/using-javascript-to-fix-12-common-browser-headaches.html We advocate at all times as much as possible the use of CSS, so that we more likely to succeed. Now the brow ...
-
Select the list of JS
Select the list of JS
-
Scroll js effects
Scroll js effects <div> <div> <img src ="<%= request.getContextPath ()%> / Letousky / jsp / img / loading.gif "> <br/> Loading ...</ div> <! - This typ ...
-
js can drag the table out
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <script language=javascript> function MouseDownToResize (obj) ( obj.mouse ...
-
javascript built-in functions Info
48. In the old browsers do not perform this JS :<!-- //--> 49. To quote a document-style JS: <script type="text/javascript" src="/blog/aaa.js"> </ script> 50. Spe ...
-
js examples of common events
<html> <head> <script type="text/javascript"> / / Which mouse button is clicked function whichButton1 (event) ( if (event.button == 2) ( alert ( "You clicked the right ...
-
[Ask] Rest nested resources helper method
(Novice, studying RestFul_Rails, rails 2.2.2) Nested resource definition is as follows: And in the project under the index view using the following code: Results page error: iterations_path undefined ...
-
jboss ejb3 Message Driven Bean
Super Medium ejb hate. . . . . . . . . . . . . . . . . . . ================================================ To configure a Message Driven Bean in a different application server parameters are not the ...
-
Oracle instant clent for ruby / rails on cygwin
Environment: XP: oracle full client, ruby, rails, gem cygwin: ruby rails, gem (the version with the XP version) Needs: for cygwin is installed under the rails platform support oci Steps: download orac ...







