Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within HTML Pages with CSS and JavaScript
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
HTML Pages with CSS and JavaScript
building a html table, ID
jite eghagha
Ranch Hand
Posts: 128
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Th script below builds a table, but it doesn't give the table an id.
I need the DOM method to _setElementId(); to achieve
<table ID="tableBarSource>...... </table>
function buildTable() { // get the reference for the body var mybody = document.getElementsByTagName("body")[0]; // creates <table> and <tbody> elements 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); }
[ October 30, 2008: Message edited by: jite eghagha ]
[ October 30, 2008: Message edited by: jite eghagha ]
Eric Pascarello
author
Posts: 15385
6
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
If you want to add an id, than add an id to your table element such as:
mytablebody.id = "myId";
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
How can I struts tag library with in javascript ?
DOM and adding a brand new select list
appendChild and IE problem
Create dynamic input text type in a table
DOM scripting - new rows in a table
More...