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
Win a copy of
Communication Patterns: A Guide for Developers and Architects
this week in the
Design and Architecture
forum!
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
Ron McLeod
Paul Clapham
Devaka Cooray
Liutauras Vilda
Sheriffs:
Jeanne Boyarsky
paul wheaton
Henry Wong
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Tim Moores
Carey Brown
Mikalai Zaikin
Bartenders:
Lou Hamers
Piet Souris
Frits Walraven
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";
Yeah, but does being a ninja come with a dental plan? And what about this tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
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...