views:

259

answers:

4

Dear All I am Using the following code to write the table, Now i wish to add subscript text,after the table text ,How can it achieved ?

My code has

  oCell = document.createElement("TD");
  oCell.innerHTML = data;
  oRow.appendChild(oCell);

how to add a subscript text followed by data ?

+3  A: 

You can use the following to append another element to the td element:

var newElem = document.createElement("sub");
newElem.appendChild(document.createTextNode("foobar"));
oCell.appendChild(newElem);
Gumbo
A: 

Or Did you mean this?:

oCell = document.createElement("TD");
oSub = document,createElement("sub");
oSub.innerHTML = data;
oCell.appendChild(oSub);
oRow.appendChild(oCell);

Hope this helps!

norbertB
+1  A: 

Why not just carry on with the innerHTML you're using

oCell.innerHTML = data+'<br /><sub>'+subText+'</sub>';

or even

oCell.innerHTML = data+'<br />'+subText.sub();

for some JavaScript 1.0, retro good? ness

meouw
A: 

oCell.innerHTML = data;

If 'data' can contain '<' or '&' characters, you've just done a blunder. Instead, use createTextNode to put plain text into HTML:

oCell.appendChild(document.createTextNode(data));
oCell.appendChild(document.createElement('sub')).appendChild(document.createTextNode(subdata));
bobince