Writing someting in a table cell through Javascript

V

Vasu

Hi!

Could anybody help me guide how to write something in between <td></
td> tags. When I try to write through document.write, it wipes the
whole table and writes on to a blank document, but when I try with
document.getElementById("respective id given by me").write, it gives
Error on page.

I'm bit puzzled. Can anyone of you help me.

Thanks in advance
Vasu
 
M

Martin Honnen

Vasu said:
Could anybody help me guide how to write something in between <td></
td> tags.


Get a reference to the table cell object e.g. with
var cell = document.getElementById('cellId');
then append text with
cell.appendChild(document.createTextNode('foo'));
If you want to insert HTML then you can use the innerHTML property e.g.
cell.innerHTML = '<b>foo</b>';

Both approaches are not specific to td elements.
 
V

Vasu

Get a reference to the table cell object e.g. with
   var cell = document.getElementById('cellId');
then append text with
   cell.appendChild(document.createTextNode('foo'));
If you want to insert HTML then you can use the innerHTML property e.g.
   cell.innerHTML = '<b>foo</b>';

Both approaches are not specific to td elements.

Hi Martin!

Thank you very much! I tried and it's working.

Vasu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,141
Messages
2,570,814
Members
47,360
Latest member
kathdev

Latest Threads

Top