DOM Table Question
I am trying to address a value on a page using DOM.
Firefox DOM Inspector shows the following:
With this, I thought that the following would get the value (i.e. 25):
It works with IE, but not with Firefox. In fact, Firefox gives a "no properties" error for the following:
Can anyone shed some light? Thanks
You've probably got a text node consisting of only white-space characters or comment node there.
Doesn't DOM Inspector include these?
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?
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>";
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."
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.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)