| | |
appendChild, invalid child type?
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
I'd like to use JavaScript to add rows to a table. It seems like an easy idea, but it occurs to me that the parent node of the rows might technically be a TBODY element. So, I'm wondering if I use appendChild to add a table row to a table element am I doing something wrong and, more importantly, is it going to fail in browser x?
For example:
Should I do something to identify the TBODY element and add the element to that instead?
Thank you.
--
-- Ghodmode
For example:
JavaScript Syntax (Toggle Plain Text)
function addTheRow() { var myTable = document.getElementById('myTable'); var newRow = document.createElement('TR'); var newCell = document.createElement('TD'); newCell.appendChild( document.createTextNode('Yeah, Baby! Yeah!!') ); newRow.appendChild( newCell ); myTable.appendChild( newRow ); } // End addTheRow function
Should I do something to identify the TBODY element and add the element to that instead?
Thank you.
--
-- Ghodmode
1
#2 Oct 26th, 2009
Do--
Typically, browsers will try to 'fix' your markup by automatically inserting tbody.
document.getElementById('myTable').getElementsByTagName('tbody')[0] to get the tbody instead of the whole table if you want to.Typically, browsers will try to 'fix' your markup by automatically inserting tbody.
Last edited by peter_budo; Oct 27th, 2009 at 10:24 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)
CodeJoust! Design + Development - Proud User of Ubuntu
![]() |
Similar Threads
- QBASIC under Windows XP (Visual Basic 4 / 5 / 6)
- fieldset and child element (JavaScript / DHTML / AJAX)
- Multiple inheritance and cross-class type casting (C++)
- java.sql.SQLException: Invalid column type: 1111 (Java)
- ASP.NET button backcolor changing from code. (ASP.NET)
- invalid directory error (Windows NT / 2000 / XP)
- Need Help Revising Array program: Visual C++ (C++)
- BackDoor. Mosucker.W (Windows NT / 2000 / XP)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Dependant combo only works one time in IE
- Next Thread: Get hash value & pass from javascript to php
Views: 408 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
ajax ajaxexample ajaxjspservlets array autoplay blackjack browser captchaformproblem checkbox child class close codes date debugger dependent developer disablefirebug dom editor element embed engine events explorer ext file flash form forms game gears getselection google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe internet java javascript javascripthelp2020 jquery jsf jsfile jump libcurl maps margin marquee masterpage math matrixcaptcha media mysql object onerror onmouseoutdivproblem onreadystatechange parent passing paypal pdf php player position post programming rated redirect runtime safari scriptlets scroll search security session shopping size software solutions sources star stars stretch synchronous toggle tweet unicode variables web webkit webservice window wysiwyg \n





