Forum Moderators: open

Message Too Old, No Replies

Javascript changing text in tag

How to change InnerText for span tag with JS

         

Demaestro

9:12 pm on Oct 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hey all,

I have done some searching but can't find anything and am hoping for some help.

I have some span tags

<span id="span_to_change">tester</span>

JAVA
******
document.getElementById('span_to_change').innerText = 'new text to display';

It doesn't error but it also doesn't change the value of the span... any insight as to what I am missing?

Drag_Racer

11:59 pm on Oct 1, 2007 (gmt 0)

10+ Year Member



I am guessing you are using Firefox for your testing? innerText is not supported in that browser.

try using innerHTML for better support across browsers. Best yet is to test what is supported, then do accordingly...

var tag = document.getElementById('span_to_change');
if (tag.innerHTML) { tag.innerHTML = 'new text to display'; }
else if (tag.innerText) { tag.innerText = 'new text to display'; }

Demaestro

2:21 pm on Oct 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks Drag_Racer... you were dead on about the browser. I don't start looking in exploder until I am closer to being finished.