Topic: Append table-row elements to existing table Pages that link to <a href="https://ozoneasylum.com/backlink?for=28730" title="Pages that link to Topic: Append table-row elements to existing table" rel="nofollow" >Topic: Append table-row elements to existing table\

 
Author Thread
Karl
Bipolar (III) Inmate

From: Phoenix
Insane since: Jul 2001

IP logged posted posted 12-12-2006 05:52 Edit Quote

Hello,

I need to append table-rows to an existing table using javascript. I would be responding to an Ajax call or clientside sort. If I have a snippet of HTML like:

<tr><td>data1</td><td>data2</tr>

Can I somehow append this to the table object?

Karl..

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

IP logged posted posted 12-12-2006 21:42 Edit Quote

All right... no magic beyond this, but I had to look at a place where I had done this before
Opps, that code only resorts existing table rows.

But it gave me the right search terms for google, so here you go
http://www.java2s.com/Code/JavaScript/HTML/InsertingRemovingRowElements.htm

so long,

->Tyberius Prime

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

IP logged posted posted 12-12-2006 22:29 Edit Quote

Indeed no magic there. Just do some document.createElement( nodeName ) ( where nodeName is td, tr, ... ) and append the resulting nodes where you want/need to. And avoid using innerHTML directly for it can lead to script injection and the like. Prefer using document.createTextNode( 'plainText' )

If you need to catch up on DOM and JavaScript, check Peter-Paul Koch's Quirksmode site or Slime's Enhancing web pages with JavaScript article



(Edited by poi on 12-12-2006 22:34)



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu