Refer to a table row using a variable?

G

Guest

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
 
M

Martin Honnen

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top