Firefox issues inserting text into span element

D

ddolheguy

I'm having trouble pre-filling information into html <span> elements
using javascript, just with Firefox. IE seems to work fine.


I'm using the following:

<script language='JavaScript'>

document.getElementbyid("lblText").innerText = 'test';

</script>

<span id='lblText'></span>

Can someone please suggest other ways I could do this?
 
R

RobG

ddolheguy said:
I'm having trouble pre-filling information into html <span> elements
using javascript, just with Firefox. IE seems to work fine.


I'm using the following:

<script language='JavaScript'>

The language attribute is deprecated, type is required:

document.getElementbyid("lblText").innerText = 'test';

innerText is an IE invention, it is not supported by Firefox (or most
other browsers). If you are writing simple content, and wish to
completely replace what is already there, then you can use the
non-standard but widely supported innerHTML:

document.getElementbyid("lblText").innerHTML = 'test';


For more complex stuff, you should probably use DOM methods.

</script>

<span id='lblText'></span>

You should have the element before the script, it will almost certainly
error anyway because when the script runs, the element hasn't been
created yet.
 
J

James Black

ddolheguy said:
I'm having trouble pre-filling information into html <span> elements
using javascript, just with Firefox. IE seems to work fine.


I'm using the following:

<script language='JavaScript'>

document.getElementbyid("lblText").innerText = 'test';

</script>

<span id='lblText'></span>

As was mentioned, using innerText is not always going to work.

So, just use:

document.getElementById("lblText").appendChild(document.createTextNode("test"));
 

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,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top