By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,774 Members | 1,394 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,774 IT Pros & Developers. It's quick & easy.

This works in IE but not in Mozilla

P: n/a
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';

Can anyone give me a clue as to how to fix this so that it will work
in both browsers?

Thanks.
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
DU
Martin wrote:
I have some functions in a script in which I'm manipulating the
innerText

Mozilla and Firefox do not support innerText. Use DOM 3 textContent()
instead for Mozilla and Firefox.

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);
() identifies parameters of a function while [] identifies the accessor
of an array.
So
thisRow = document.getElementById('TableX').rows[1];
will work in both browsers.
thisRow.style.background = 'white';
thisRow.style.backgroundColor = 'white';

Can anyone give me a clue as to how to fix this so that it will work
in both browsers?

Thanks.


DU
--
The site said to use Internet Explorer 5 or better... so I switched to
Mozilla 1.7.6 :)
Jul 23 '05 #2

P: n/a
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
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.