Martin wrote:
I have some functions in a script in which I'm manipulating the
innerText and background colors of certain rows in a table. The lines
below work OK in IE but when I try them in Mozilla, I get an error
that says: "document.getElementById('TableX').rows is not a
function".
thisRow = document.getElementById('TableX').rows(1);
thisRow.style.background = 'white';
The rows collection is like a reduced functionality array, you must
address its members the same as elements in an array:
thisRow = document.getElementById('TableX').rows[1];
And the correct way to modify an element's background color using its
style object is:
this.style.backgroundColor = 'white';
You should also do feature detection before using either
getElementById or style:
if (document.getElementById) {
thisRow = document.getElementById('TableX').rows[1];
}
if (thisRow.style) {
thisRow.style.backgroundColor = 'white';
}
Of course you only need to test for these once, and it may be helpful
to provide alternative methods for browsers that don't support them.
Have a look at the group FAQ for help on this and the square/round
bracket issue.
<URL:http://www.jibbering.com/faq/>
Can anyone give me a clue as to how to fix this so that it will work
in both browsers?
As was noted in DU's post, innerText will not work in
Firefox/Mozilla (or most browsers other than IE).
There are some suggestions in the thread below on cross-browser
implementations of innerText functionality (please excuse wrapping)
or search for 'innerText' in this newsgroup on 27 March 2005:
<URL:http://groups-beta.google.com/group/comp.lang.javascript/browse_thread/thread/77f653baa1044486/ed976a3594350a25?q=innerText&rnum=2#ed976a3594350a 25>
--
Rob