var.innerHTML where var is a variable!!

K

Keiron Waites

Is there any way to use a variable.innerHTML = ""; instead of text.innerHTML
= "";? It doesn't seem to work for me.

Thanks,

Keiron
 
L

Lasse Reichstein Nielsen

Keiron Waites said:
Is there any way to use a variable.innerHTML = ""; instead of text.innerHTML
= "";? It doesn't seem to work for me.

I am sorry, but I can't see what you are trying to do.

The "innerHTML" property is a property of Document Object Model nodes,
not of text strings. You can do
document.getElementById("elemName").innerHTML = "<em>foo</em>";
and you can do
var variable = document.getElementById("elemName");
variable.innerHTML = "<em>foo</em>";
but you can't write
"text string".innerHTML = "<em>foo</em>";

I am afraid you will ahve to be a little more explicit about what you
are trying to do, if we are to be able to help you.

(and as a side note, you can't have a variable called "var". That is
a reserved word in Javascript.)

/L
 
M

Martin Honnen

Keiron said:
Is there any way to use a variable.innerHTML = ""; instead of text.innerHTML
= "";? It doesn't seem to work for me.

Use
var element;
if (document.all) {
element = document.all[variable];
}
else if (document.getElementById) {
element = document.getElementById(variable);
}
if (element) {
element.innerHTML = ...
}
 

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

Forum statistics

Threads
474,079
Messages
2,570,574
Members
47,206
Latest member
Zenden

Latest Threads

Top