www.webdeveloper.com
Results 1 to 6 of 6

Thread: DOM Table Question

  1. #1
    Join Date
    Dec 2005
    Posts
    264

    DOM Table Question

    I am trying to address a value on a page using DOM.

    Firefox DOM Inspector shows the following:
    -DIV (ID=my_id)
    --TABLE
    ---TBODY
    ----TR
    ----TR
    -----TD
    ------TEXT (DATA=25)

    With this, I thought that the following would get the value (i.e. 25):
    Code:
    document.getElementById("my_id").getElementsByTagName('tr')[1].firstChild.firstChild.data
    It works with IE, but not with Firefox. In fact, Firefox gives a "no properties" error for the following:
    Code:
    alert(document.getElementById("my_id").firstChild.nodeType);
    Can anyone shed some light? Thanks

  2. #2
    Join Date
    Jul 2005
    Location
    USA
    Posts
    3,910
    You've probably got a text node consisting of only white-space characters or comment node there.
    Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions

    Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.

    Check out my blog.

  3. #3
    Join Date
    Dec 2005
    Posts
    264
    Doesn't DOM Inspector include these?

  4. #4
    Join Date
    Dec 2005
    Posts
    264
    I think I might have stumbled on to the cause. I am using innerHTML to generate the table inside a DIV (PHP is used to modify the values, but I have removed the PHP portion). Firefox "DOM Inspector" shows the individual table DOM elements. IE can also access the individual table DOM elements. The Firefox browser, however, doesn't appear to be able to access the table elements (odd that DOM Inspector shows them). Could innerHTML be causing the problem?

    Code:
    document.getElementById("my_id").innerHTML="<table border=1 width=100% cellspacing=0 cellpadding=0><tbody><tr><td align=center>V1</td><td align=center>V2</td></tr><tr><td align=center>1</td><td align=center>2</td></tr></tbody></table>";

  5. #5
    Join Date
    Jan 2005
    Posts
    3,067
    According to the Mozilla Developers shown here

    Although is can be used to, innerHTML "should never be used to write parts of a table—W3C DOM methods should be used for that—though it can be used to write an entire table or the contents of a cell."

  6. #6
    Join Date
    Jul 2005
    Location
    USA
    Posts
    3,910
    Ah. I've heard but not confirmed that when innerHTML is used to add elements to a page they appear but aren't added to the DOM like they would be if you use DOM1+ methods.
    Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions

    Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.

    Check out my blog.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles