Setting the innerText / innerHTML on a <span>

K

Kerri

Hi,

I have a span as below.

<span id="lblTest" style="color:#FF0033;font-
weight:bold;">This is a test.</span>

When the user clicks a checkbox I call below code to set
my span text to blank.



var el = document.MyForm.getElementById("Test");
el.innerHTML="";

I have also tried using innerText property.

What am I doing wrong here?

Thanks,
Kerrt.
 
B

Bob Barrows

Kerri said:
Hi,

I have a span as below.

<span id="lblTest" style="color:#FF0033;font-
weight:bold;">This is a test.</span>

When the user clicks a checkbox I call below code to set
my span text to blank.



var el = document.MyForm.getElementById("Test");
el.innerHTML="";

I have also tried using innerText property.

What am I doing wrong here?
You're not using the span's id in your getElementById call. The id is
"lblTest", not "Test"

Bob Barrows

PS. ASP is a server-side technology. Your question deals with client-side
dhtml code, making it off-topic for this newsgroup. In the future please
post your questions to the appropriate newsgroup (there are several public
newsgroups with "dhtml" in their names - pick the one that seems most
appropriate) - you will get quicker, more fucussed assistance.
 
K

Kerri

Sorry Bob.

My post was wrong.

In my code I am doing this correctlt but it does'nt work.

Any ideas.

Kerri.
 
A

Aaron Bertrand [MVP]

You're not using the span's id in your getElementById call. The id is
"lblTest", not "Test"

Also, a span is not part of a form's hierarchy, so using the form name in
the call doesn't make sense.
 
B

Bob Barrows

Kerri said:
Sorry Bob.

My post was wrong.

In my code I am doing this correctlt but it does'nt work.

Any ideas.
Please tell us what the symptoms are. Without that info, all we can do is
guess.

Aaron made a good point which I missed. This:
var el = document.MyForm.getElementById("Test");
el.innerHTML="";

Should be this:
var el = document.getElementById("Test");
el.innerHTML="";


Bob Barrows
 

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
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top