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

Refer to a table row using a variable?

P: n/a
Hi, I hope someone can help me with what is probably quite an easy
question!

I need to store a string in a variable, and then use that variable to
refer to a table row. For example:

var row = 'row10';
[row].style.backgroundcolor='white';

My row is defined as:

<tr id='row10'>

If I use "row10.style.backgroundcolor='white' then it works, but if I
use the variable then it doesn't. I have tried it with and without
square brackets. What I am I doing wrong?

Thanks
Mark

Jan 14 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a


sp**@pinkdoggy.net wrote:

var row = 'row10'; My row is defined as:

<tr id='row10'>


Have you never heard about
var element = document.getElementById(row);
then? That is the main way in the W3C DOM to access an element by the
value of its id attribute, whether that is a tr element or just about
any other element in a HTML document.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jan 14 '06 #2

P: n/a
Thank you. I had never heard of that, but it's working now.

Cheers
Mark

Jan 14 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.