Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2002
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Tables and the DOM

    I've been having some problems with Tables and the DOM and
    JavaScript.

    Anyway, I have a table tag in my page, and because of the general nature
    of the table (it contains 64 squares (8X8, think chess)), and I've been trying to
    do something like this:

    Code:
    for (i=0; i<8; i++) {
    var tagA = document.createElement ("tr")//it's not this
    document.getElementById("idname").firstChild.appendChild(tagA)
     for (ii=0; ii<8; ii++) {//it's not this
    var tagB = document.creatElement ("td")
    tagB.setAttribute ("@name", @value) //it's not this
    document.getElementById("idname").firstChild.childNodes[i].appendChild(tagB)
    }
    }
    //idname is the id of the table tag, and firstChild is it's only child
    //with a tag name TBODY, it seems to get Appended by itself, and
    //it always encases the contents of the table
    //the @isn't actually in the code, I'm just using it as a abbreviation
    It's not the code, because no matter how I change it, it always says:
    "Exception Occurred" or "Unknown Runtime Error",
    depending on whether I tried to set the attribute "innerHTML", or append a Node.

    It seems to me, that the table is treated as a seperate entity all to itself.

    So my question#1 is:
    Is the TABLE element write protected? Because the only way I've ever been able
    to modify one is by first removing it and using document.write to write a new one out

    Guardian

  • #2
    New Coder
    Join Date
    Jul 2002
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Turns out that the createElement Method worked, but when I
    tried using it the first time round, I forgot about the TBODY ?tag?.
    Still, the innerHTML couldn't be set inside the TBODY tag, only
    within it's children... so the innerHTML still seems a little quirky,
    guess I'll just stick with the createElement method...

    Sorry for the disturbance.

    Guardian

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    185
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you're wanting to access table contents by row and column more directly, check the links I posted on the other thread - appendChild and document.createElement


  •  

    Posting Permissions

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