Tables and outerHTML

Results 1 to 2 of 2

Thread: Tables and outerHTML

  1. #1
    Join Date
    Dec 1969

    Default Tables and outerHTML

    I am trying to add Rows to a table. Here is what I have that WILL work.<BR><BR>&#060;Script language="JavaScript"&#062;<BR>var row, col<BR>function AddItem()<BR>{ <BR>&nbsp&nbsp&nbsp&nbsp var theTable = document.getElementById("mytable");<BR>&nbsp&nbsp& nbsp&nbsp row = theTable.rows.length - 1; <BR>&nbsp&nbsp&nbsp&nbsp theTable.insertRow(row);<BR>&nbsp&nbsp&nbsp&nbsp for(col=0;col&#060;7;col++)<BR>&nbsp&nbsp&nbsp&nbs p {<BR>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp theTable.rows[row].insertCell(col);<BR>&nbsp&nbsp&nbsp&nbsp&nbsp&nbs p&nbsp&nbsp theTable.rows[row].cells[col].innerHTML = "Some Stuff Here"<BR>&nbsp&nbsp&nbsp&nbsp }<BR>}<BR>&#060;/Script&#062;<BR><BR>My question:<BR><BR>How do I insert cells in a way that I can dictate the cell formatting? I have used innerHTML with no trouble. But everytime I try to use outerHTML, it does unpredictable things. I don&#039;t understand outerHTML obviously. Can someone explain outerHTML or another way to format added cells?

  2. #2
    Join Date
    Dec 1969

    Default Try setting the style information..

    .. if you want the cell to have a gray background:<BR>theTable.rows[row].cells[col].style.backgroundColor = "#c0c0c0#";<BR><BR>I think that&#039;ll work. Just find a reference on the style property.<BR><BR>-Doug

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts